2024-04-30 01:16:37 发布
网友
我对firebase非常陌生,老实说,我发现很难编写查询。我正在使用firebase_admin编写一个python脚本,我希望查询/答案是python代码,但任何其他编程语言都可以
firebase_admin
这是我的一个文档,一个文档包含photos集
photos
photos: { id1: true id2: true }
我想通过ale检索照片对象中ID为的所有项目,该查询是什么
如图Firebase documentation on simple queries所示:
# Create a reference to the photos collection ref = db.collection('documents') # Create a query against the collection query_ref = ref.where(u'photos.id1', u'==', True)
有关.表示法,请参阅fields in nested objects上的文档
.
请注意,您可能希望更改数据模型,以便对该数据使用数组,如arrays can now be used to model mathematical sets。在文档中使用如下数组:
user: ['id1', 'id2']
然后,您可以使用以下选项进行筛选:
photos_ref = db.collection('documents') query = photos_ref.where(u'photos', u'array_contains', u'id1')
要将项添加/删除到此数组中,请参阅updating elements in an array上的文档
如图Firebase documentation on simple queries所示:
有关
.
表示法,请参阅fields in nested objects上的文档请注意,您可能希望更改数据模型,以便对该数据使用数组,如arrays can now be used to model mathematical sets。在文档中使用如下数组:
然后,您可以使用以下选项进行筛选:
要将项添加/删除到此数组中,请参阅updating elements in an array上的文档
相关问题 更多 >
编程相关推荐