-
Notifications
You must be signed in to change notification settings - Fork 376
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
Firestore Transaction get() returning QuerySnapshot but it should be DocumentSnapshot #344
Comments
Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information. |
Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight. |
Your code compiles and works just fine for me. Here it is with some TypeScript annotations added for clarity (this compiles successfully):
|
One possibility is you're running the transaction on a collection reference, which extends |
@hiranya911 Thanks, i first made sure i was running the transaction in a document reference and it was indeed a document reference, so i finally made it work by explicitly declaring the types for DocumentReference and DocumentSnapshot as you did. I had my code inside a function so i did it like this:
I don't know why, but while deploying the linter inferred doc as QuerySnapshot even though it was not. There may be something to consider. Thanks again. |
Transaction.get() returns a DocumentSnapshot if you pass a DocumentReference (https://github.com/googleapis/nodejs-firestore/blob/master/dev/src/transaction.js#L89) and a QuerySnapshot if you pass a Query or a CollectionReference (https://github.com/googleapis/nodejs-firestore/blob/master/dev/src/transaction.js#L97). Everything else should get rejected. Please let us know if you still encounter this issue. I am closing this as it looks like it is working for you now. |
Environment
The problem
I'm trying to reproduce a firestore transaction with this sample code from the firebase documentation https://firebase.google.com/docs/firestore/manage-data/transactions?hl=es-419
However in
db.runTransaction(t => { return t.get(cityRef).then(doc => { ... } ...
it is say that doc must return a DocumentSnapshot, but it returns a QuerySnapshot. Even that way i can't obtain the DocumentSnapshot from doc, so there is a problem with the documentation and i'm not sure if there is also a bug with the return value.The text was updated successfully, but these errors were encountered: