ID/密钥上的Firebase集合组查询 [英] Firebase Collection Group Query on Id / Key
问题描述
我一直关注以下文档: https://firebase.google.com/docs/firestore/query-data/queries#collection-group-query
I have been following along the following document: https://firebase.google.com/docs/firestore/query-data/queries#collection-group-query
我的数据结构大致如下:
My data structure roughly looks like this:
/teams/{teamid}
{
displayName: "Company X Team",
owner: "userid",
}
/teams/{teamid}/invites/{emailAddressAsKey}
{
someProp: "my data"
}
在我的Web应用程序中,我想搜索所有不同的团队记录,以找到一个ID/密钥等于我传递的电子邮件地址的邀请.在阅读了文档之后,我认为集合组查询是什么我在找.但是,我的情况与示例不完全匹配.我想匹配键,而不是文档中的道具.我想我可以再次添加电子邮件地址作为道具,但这感觉不对.
In my web app I want to search through all the different teams records to find an invite who's id/key is equal to the email address that I pass in. After reading through the documentation, I think a Collection Group Query is what I'm looking for. However, my situation doesn't exactly match the example. I want to match on the key, not a prop within the document. I suppose I could add the email address again as a prop, but that doesn't feel right.
推荐答案
您可以在 FieldPath.documentId()
的帮助下解决此问题,就像下面的代码行一样:
You can solve this with the help of FieldPath.documentId()
like in the following line of code:
db.collectionGroup('teams').where(firebase.firestore.FieldPath.documentId(), '==', 'teams/teamId').get()
此查询将返回具有特定团队ID的所有文档.
This query will return all documents with a specific team id.
这篇关于ID/密钥上的Firebase集合组查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!