question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FR: allow DocumentReference.select similar to Query.select

See original GitHub issue

Hey guys, I have been snooping around the source code and documentation. It seems like the only way to do apply a field mask to the result and returns only the specified subset of fields is through the Query.select method. https://cloud.google.com/nodejs/docs/reference/firestore/0.8.x/Query#select https://github.com/googleapis/nodejs-firestore/blob/master/src/reference.js#L1080

Is there any plan or ways to enable the same feature when getting a single document via DocumentReference? The code seems plenty of references to https://cloud.google.com/firestore/docs/reference/rest/v1beta1/DocumentMask which is used to restrict a get or update operation on a document to a subset of its fields, but I didn’t have any luck tracking down usage of this in DocumentReference.get

Relevant Code:

// based on the select example at https://cloud.google.com/nodejs/docs/reference/firestore/0.8.x/Query#select
let collectionRef = firestore.collection('col');
let documentRef = collectionRef.doc('doc');

documentRef.set({x:10, y:5}).then(() => {
  return collectionRef.where('x', '>', 5).select('y').get();
}).then((res) => {
  console.log(`y is ${res.docs[0].get('y')}.`);
});
// would like to be able to also do
documentRef.select('y').get().then((snapShot) => {
  console.log(`snapShot only has one field ${snapShot}`);
  // Expected output: {y: 5}
});

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
schmidt-sebastiancommented, Nov 5, 2018

We are currently debating on how to best implement this. Please stay tuned.

0reactions
triplefcommented, Nov 5, 2018

It would be great to have this issue re-opened for consideration.

As mentioned above, the comments in firebase/firebase-js-sdk#212 don’t apply to the Admin SDK. It would be great to have a DocumentReference.select() function implemented there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FR. allow DocumentReference.select similar to Query ... - GitHub
I have been snooping around the source code and documentation. It seems like the only way to do apply a field mask to...
Read more >
DocumentReference | Firebase JavaScript API reference
Applies a custom data converter to this DocumentReference, allowing you to use your own custom model objects with Firestore. When you call set(),...
Read more >
Cloud Firestore: how to fetch a document reference inside my ...
Every comment object has a "doc ref" to the user who posted. I need a query that will return a list of comments...
Read more >
Querying and filtering data | Firestore - Google Cloud
Firestore provides powerful query functionality for specifying which documents you want to retrieve from a collection or collection group. These queries can ...
Read more >
Document from Reference - FlutterFlow Docs
Select the Query Type as Document from Reference. ... You can follow similar steps for using the record data on the other widgets...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found