Abh*_*rty 14 android node.js firebase google-cloud-functions google-cloud-firestore
我是Android开发人员,最近我开始研究基于firebase云功能和firestore数据库的项目.我正在编写一个HTTP触发器函数,该函数将接受两个参数并将该参数值与firestore数据值进行比较,如果值匹配,则返回true或其他错误的响应.
重复问题:
是的,有一些问题已经被问到我的相关但是它们并不相似:
Firebase文档说:
Cloud Firestore支持创建,更新,删除和写入事件
我想从HTTP触发器读取firestore值.
我尝试过的:
exports.userData = functions.https.onRequest((req, res) => {
const user = req.query.user;
const pass = req.query.pass;
});
Run Code Online (Sandbox Code Playgroud)
我几乎坚持这一部分.任何帮助将不胜感激.谢谢
PS我对JS/TypeScript/NodeJS的知识非常有限
Rua*_*uan 35
有点晚了,但对于其他任何一个绊脚石的人来说.
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)
})
});
Run Code Online (Sandbox Code Playgroud)
感谢阮的回答,这里有一个onCall(..)变化的例子:
exports.fireGetColors = functions.https.onCall((data, context) => {
return new Promise((resolve, reject) => {
var colors = {};
var db = admin.firestore();
db.collection('colors')
.get()
.then(snapshot => {
snapshot.forEach(doc => {
var key = doc.id;
var color = doc.data();
color['key'] = key;
colors[key] = color;
});
var colorsStr = JSON.stringify(colors, null, '\t');
console.log('colors callback result : ' + colorsStr);
resolve(colors);
})
.catch(reason => {
console.log('db.collection("colors").get gets err, reason: ' + reason);
reject(reason);
});
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12994 次 |
| 最近记录: |