Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Query only specific field with firestore

I use this code to get a collection snapshot from Firestore.

firestore().collection('project').where('userID', '==', authStore.uid).onSnapshot(onResult, onError);

This returns a huge amount of data, but I only need a few fields. Is it possible to query only a specific field? For example, if I only need the projectName and the creationDate fields.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Is it possible to query only a specific field?

No, that is not possbile. A Firestore listener fires on the document level. This means that you’ll always get the entire document.

For example if I only need the projectName and the creationDate fields.

You cannot only get the value of a specific set of fields. It’s the entire document or nothing. If you, however, only need to read those values and nothing more, then you should consider storing them in a separate document. This practice is called denormalization, and it’s a common practice when it comes to NoSQL databases.

You might also take into consideration using the Firebase Realtime Database, for the duplicated data.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading