FirebaseExtended / firestoreodm-flutter

BSD 3-Clause "New" or "Revised" License
33 stars 9 forks source link

Support collection groups #20

Open Lyokone opened 1 month ago

Lyokone commented 1 month ago
  How can I do a collection group query with a sub-collection? It looks like right now I have to have a parent (collectionId) first and then get the sub-collection part of that collection. But I want to be able to query against all sub collection documents.

I have:

@Collection<Configuration>('configurations')
@Collection<SharedWith>('configurations/*/sharedWith')
final configurationRef = ConfigurationCollectionReference();

And I want to be able to query like I would if I had created a group query

final Query<Map<String, dynamic>> _configSharedWith = _firestore.collectionGroup('sharedWith');
// Query across all sub collection documents
final sharedWith = await _configSharedWith.where('userId', isEqualTo: userId).get();

Originally posted by @FXschwartz in https://github.com/firebase/flutterfire/discussions/7475#discussioncomment-3311361

Copied from https://github.com/firebase/flutterfire/issues/9751