所以我在网上到处找,我似乎无法弄清楚如何让它工作。
我想要实现的是找到在他们的设备下拥有相同设备的所有用户。这是 Firestore 数据库的结构: 数据库图像
所以最近 Firebase 发布了他们的 Javascript 库的 5.3.0 版,在他们的发行说明中指出:
添加了“array-contains”查询运算符,与 .where() 一起使用以查找数组字段包含特定元素的文档。
我试图在 .where() 中使用这个“数组包含”,但我没有成功。这是我的代码:
admin.firestore().collection("users").where("devices",'array-contains', id)
//I get id from another place, i know that id is valid
这是我从 firebase 函数日志中得到的错误:
未处理的错误错误:参数“opStr”不是有效的 FieldComparison。运算符必须是“<”、“<=”、“==”、“>”或“>=”之一。在 Object.exports.(anonymous function) [as isFieldComparison] (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/validate.js:89:23) 在 CollectionReference.where (/ user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/reference.js:1095:18) atexports.checkIfDeviceIdValid.functions.https.onCall (/user_code/index.js:23:50 ) 在 /user_code/node_modules/firebase-functions/lib/providers/https.js:330:32 在下一个(本机)在完成 (/user_code/node_modules/firebase-functions/lib/providers/https.js:25:58 ) 在进程中。
这是我的 package.json 中的依赖项:
"dependencies": {
"@google-cloud/firestore": "^0.15.4",
"firebase-admin": "~5.13.0",
"firebase-functions": "^2.0.2"
}
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮助我解决这个问题并向我展示如何做到这一点的例子,我将不胜感激。谢谢你。
javascript firebase google-cloud-functions google-cloud-firestore