我是Android开发人员,最近我开始研究基于firebase云功能和firestore数据库的项目.我正在编写一个HTTP触发器函数,它将获取两个参数并将该参数值与firestore数据值进行比较,如果值匹配,则返回true或其他错误的响应.
重复问题:
是的,有一些问题已经被问到我的相关但是它们并不相似:
> Firestore + cloud functions: How to read from another document
> Firebase HTTP Cloud Functions – Read database once
Firebase文档说:
Cloud Firestore supports create, update, delete, and write events
我想从HTTP触发器读取firestore值.
我尝试过的:
exports.userData = functions.https.onRequest((req, res) => {
const user = req.query.user;
const pass = req.query.pass;
});
我几乎坚持这一部分.任何帮助将不胜感激.谢谢
附:我对JS / TypeScript / NodeJS的知识非常有限
解决方法:
有点晚了,但对于其他任何一个绊脚石的人来说.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.someMethod = functions.https.onRequest((req, res) => {
var stuff = [];
var db = admin.firestore();
db.collection("Users").doc("7vFjDJ63DmhcQiEHwl0M7hfL3Kt1").collection("blabla").get().then(snapshot => {
snapshot.forEach(doc => {
var newelement = {
"id": doc.id,
"xxxx": doc.data().xxx,
"yyy": doc.data().yyy
}
stuff = stuff.concat(newelement);
});
res.send(stuff)
return "";
}).catch(reason => {
res.send(reason)
})
});