Firestore:按文档数组中的项目查询 [英] Firestore: Query by item in array of document
问题描述
我有一个文档用户,它的键名为照片。这是一个要保存的字符串数组,即照片文档的ID。
I have a document "user" which has a key called "photos". Here is an array of strings being saved, namely the IDs of the "photo" documents.
我想通过照片字段查询用户:我想要所有在照片属性中拥有此ID的用户。
I want to query "user" by this "photos" field: I want all users who have this ID in the "photos" property.
是否可以通过Firestore做到这一点?
Is this possible through firestore?
推荐答案
添加了与 .where()一起使用的数组包含查询运算符,以查找其中数组字段包含特定元素的文档。
Added 'array-contains' query operator for use with .where() to find documents where an array field contains a specific element.
https:// firebase .google.com / support / release-notes / js 5.3.0
更新:也可以在<$ c $中使用c> @ google-cloud / firestore : https ://github.com/googleapis/nodejs-firestore/releases/tag/v0.16.0
更新2 https://firebase.googleblog.com/2018/08/better-arrays-in-cloud-firestore.html
更新3 现在可以在Admin Node.js SDK v6.0.0中使用 https://github.com/firebase/firebase-admin-node/releases
Update 3 now available in Admin Node.js SDK v6.0.0 https://github.com/firebase/firebase-admin-node/releases
这篇关于Firestore:按文档数组中的项目查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!