[英]firebase cloud functions return nested documents
I'm using firestore database and I am trying to retrieve data from a collection, but the data is related to another document in another collection.我正在使用 firestore 数据库,我正在尝试从集合中检索数据,但数据与另一个集合中的另一个文档相关。
What I'm trying to do is the following:我想要做的是以下几点:
exports.acc = functions.https.onRequest(async (req, res) => {
let docRef = admin.firestore().collection('LoggedIn').doc('CurrentLogin');
snapshot = await docRef.get();
doc = snapshot.data();
usr = doc["Email"];
// I want to get the Level from the Current Logged In user (the 'usr' below)
let docRef1 = admin.firestore().collection('Accounts').doc(usr);
snapshot1 = await docRef1.get();
doc1 = snapshot1.data();
usr1 = doc1["Level"];
return res.send(usr1);
});
I've spent the last day just trying and trying with no luck, if I do one document it works, for example when I do this:我花了最后一天尝试,但没有运气,如果我做一个文档,它就可以工作,例如当我这样做时:
exports.acc = functions.https.onRequest(async (req, res) => {
let docRef = admin.firestore().collection('LoggedIn').doc('CurrentLogin');
snapshot = await docRef.get();
doc = snapshot.data();
usr = doc["Email"];
return res.send(usr);
});
It really returns the email address for the current logged in user.它确实返回当前登录用户的 email 地址。
why is the code above not working?为什么上面的代码不起作用? what am I doing wrong?我究竟做错了什么?
Any help is greatly appreciated任何帮助是极大的赞赏
Thank you:)谢谢:)
I fixed the problem, turns out it was because the 'Level' is an integer value, so I had to add toString(), like that:我解决了这个问题,原来是因为“Level”是一个 integer 值,所以我必须添加 toString(),如下所示:
usr1 = doc1["Level"].toString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.