简体   繁体   中英

How to query a single field from a Firestore document in REST API?

I followed some tutorial to be able to get documents. It is working just fine but now how would I query a single field from a document? I can find answers talking vaguely about the way but no actual syntax example.

Here is my GET code:

 //View a user app.get('/users/:userId', (req, res) => { firebaseHelper.firestore .getDocument(db, usersCollection, req.params.userId) .then(doc => res.status(200).send(doc)); }) 

I don't recognize any of the code you've shown as Firestore client library API (what are firestoreHelper and getDocument ?). But I can tell you that none of the client library APIs for any platform allow you to read a single field from a document. If you read any document, you must read the entire document, even if you only want one field. There are technical reasons for this limitation.

If you wish to limit the amount of data you read in a single query, then split up the fields of your documents into multiple documents in multiple collections, and read only the documents whose fields you want to fetch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM