简体   繁体   English

Firestore Group Collection 文件的唯一性

[英]Firestore Group Collection documents uniqueness

I am trying to do a collection group query from firebase firestore.我正在尝试从 firebase firestore 进行收集组查询。 But I am worried that there might be complications becauase most documents in a subcollection have the same ids as documents in other subCollections.但我担心可能会出现并发症,因为子集合中的大多数文档与其他子集合中的文档具有相同的 ID。 So when I am querying all documents in collection group, I don't know if I will not run into errors or be able to distinguish between the documents.所以当我在查询集合组中的所有文档时,我不知道我是否会遇到错误或能够区分这些文档。

return _fsInstance
    .collectionGroup("subCollection").where('date' isEqualTo: "$date");

A single collection cannot have documents with same IDs but you can have documents with same ID in different (sub)collections.单个集合不能包含具有相同 ID 的文档,但您可以在不同(子)集合中包含具有相同 ID 的文档。 When you run your query, each document in the QuerySnapshot will have its own DocumentReference.当您运行查询时,QuerySnapshot 中的每个文档都会有自己的 DocumentReference。 For example:例如:

/col/doc/(subCol1)/doc1

/col/doc/(subCol2)/doc1

Here, both subCol1 and subCol2 have document with ID doc1.在这里,subCol1 和 subCol2 都有 ID 为 doc1 的文档。 The query won't cause any issues but when you read doc.id they'll be same.该查询不会导致任何问题,但当您阅读doc.id时,它们将是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM