Home > Mobile >  Query only specific field with firestore
Query only specific field with firestore

Time:05-14

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

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

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.

CodePudding user response:

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.

  • Related