FR: allow DocumentReference.select similar to Query.select
See original GitHub issueHey 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:
- Created 6 years ago
- Comments:7 (3 by maintainers)
We are currently debating on how to best implement this. Please stay tuned.
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.