-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: allow DocumentReference.select similar to Query.select #42
Comments
I have also filed this against firebase/firebase-js-sdk#272 since I am not sure where the source of development on the firestore part is housed. |
firebase/firebase-js-sdk#212 answers this |
@goldensunliu Are you sure that that the issue in the Firebase JS SDK really answers this? I don't see a problem in the ADMIN SDK to add such a method to the DocumentReference. As far as I know, there is no caching in the ADMIN SDK, so it should be no problem to allow a snippet/method like this: admin.firestore().document("path/to/a/document").select("y").get().then(snap => {
console.log(`snapShot only has one field ${snap.data()}`);
// Expected output: {y: 5}
}); Or am I wrong? |
@IchordeDionysos you're right: the comments in firebase/firebase-js-sdk#212 specifically relate to the mobile clients and the complications of interacting with the cache while offline. These concerns do not apply to the nodejs or admin SDKs.
In the meantime you can work around this by writing the following instead: const projectId = // ... your project id
const path = 'path/to/a/document';
db.document(path)
.parent // i.e. the collection containing the document
.where('__name__', '==', `projects/${projectId}/databases/(default)/documents/${path}`)
.select(...) Note that the result will be a query snapshot rather than a document snapshot, but it should get you what you want in the short term. @schmidt-sebastian holler if I got this wrong. |
A more concise version would be as follows:
|
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 |
We are currently debating on how to best implement this. Please stay tuned. |
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:
The text was updated successfully, but these errors were encountered: