-
Notifications
You must be signed in to change notification settings - Fork 2.2k
How to use a query in new modular firestore #3203
-
Hello everyone,
I am moving from compat to modular firestore version. I have the following function with an optional query argument:
getCollection<T>(collectionName: string, queryFn?: QueryFn): AngularFirestoreCollection<T> { return this.firestore.collection<T>(collectionName, queryFn); }
With the modular version I probably will go like this:
getCollection(collectionName: string, queryFn?: QueryFn): CollectionReference<DocumentData> { return collection(this.firestore, collectionName); }
Unfortunately I did not find anything how to pass my (optional) Query here. Do you have any suggestions how I I can do this?
Regards Nils
Beta Was this translation helpful? Give feedback.
All reactions
Hi there !
I use the following approach, perhaps it could help you.
getUsers(): Observable<User[]> { const usersCollection: CollectionReference<User> = collection( this.firestore, 'users' ) as CollectionReference<User>; return collectionData<User>( query(usersCollection, orderBy('createdAt', 'desc')), { idField: 'uid', } ); }
Have a good day buddy !
Replies: 1 comment 1 reply
-
Hi there !
I use the following approach, perhaps it could help you.
getUsers(): Observable<User[]> { const usersCollection: CollectionReference<User> = collection( this.firestore, 'users' ) as CollectionReference<User>; return collectionData<User>( query(usersCollection, orderBy('createdAt', 'desc')), { idField: 'uid', } ); }
Have a good day buddy !
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 3
-
Awesome. This helped me a lot. My biggest problem was, that my IDE (PHP Storm) did not import all functions and types correct (some were imported from compat, others were not automatically detected).
Beta Was this translation helpful? Give feedback.
All reactions
-
🎉 1