【发布时间】:2020-05-27 06:10:29
【问题描述】:
在我下面的应用程序中,我首先获取 4 个玩家的 uid,然后查询每个用户名和设备令牌 ID,它们分别存储在我的数据库中。
为了保存读取,我现在将这两个信息存储在一个数组中的同一个文档中。由于我是 JavaScript 新手,我现在不知道如何从 Firestore 获取此数组并访问该数组中存储的数据。
我知道如何使用 Android/Java 从 Firestore 获取数组,但这似乎不适用于 JavaScript。
非常感谢任何帮助!
这是我在云函数中使用的代码:
...
// This is where the array is stored, I now need to get the array and access the data of it
admin.firestore().collection("User").doc(uid_player_1).collection("User Info").doc("UsernameToken").get().then(queryResult =>{
// You need to get the array that is stored there. The first value (0) there is the username, the second is the device token
console.log(queryResult)
});
...
这是我得到的日志:
QueryDocumentSnapshot {
_fieldsProto:
{ usernameToken: { arrayValue: [Object], valueType: 'arrayValue' } },
...
这里是包含该数组的文档的集合:
【问题讨论】:
-
您显示的文档似乎与您查询的文档不匹配。他们有不同的路径。
-
@DougStevenson 我编辑了我的帖子。现在您会看到我正在查询的文档,其中包含图像中的数组
-
你能展示一下你在执行这一行时得到了什么
console.log(queryResult)
标签: javascript node.js firebase google-cloud-firestore google-cloud-functions