Biomanuel
Biomanuel

Reputation: 11

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");

Upvotes: 1

Views: 54

Answers (1)

Dharmaraj
Dharmaraj

Reputation: 50920

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.

Upvotes: 2

Related Questions