简体   繁体   中英

Firestore Group Collection documents uniqueness

I am trying to do a collection group query from 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. 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. When you run your query, each document in the QuerySnapshot will have its own DocumentReference. For example:

/col/doc/(subCol1)/doc1

/col/doc/(subCol2)/doc1

Here, both subCol1 and subCol2 have document with ID doc1. The query won't cause any issues but when you read doc.id they'll be same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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