javascript - firebase 云函数返回嵌套文档
问题描述
我正在使用 firestore 数据库,我正在尝试从集合中检索数据,但数据与另一个集合中的另一个文档相关。
我想要做的是以下几点:
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);
});
我花了最后一天尝试,但没有运气,如果我做一个文档,它就可以工作,例如当我这样做时:
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);
});
它确实返回了当前登录用户的电子邮件地址。
为什么上面的代码不起作用?我究竟做错了什么 ?
任何帮助是极大的赞赏
谢谢 :)
解决方案
我解决了这个问题,原来是因为'Level'是一个整数值,所以我不得不添加toString(),就像这样:
usr1 = doc1["Level"].toString();
推荐阅读
- scala - Scala:从特征实例化时使用 def 或 val?
- unity3d - 找不到 java.lang.Object com.unity3d.player.ReflectionHelper.nativeProxyInvoke 的实现
- wordpress - Wordpress wp-admin 重定向到 EC2 域
- r - R xlsx Excel 数字格式
- c++ - LinkedList ADT 指针块
- java - 如何在 Java 中使用 python 代码?
- swift - Xcode 10.1 swift 4.2 运算符重载导致编译器警告:“通过此函数的所有路径都将调用自身”
- sql - 黑斑羚每月的最后一天
- typescript - TypeORM-findOne 返回意外值
- django - 如何在 Django 中跨 3 个表编写查询集?