Skip to content
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

Realtime Firestore query results in error for "docChanges" #824

Closed
Thkasis opened this issue May 15, 2018 · 11 comments
Closed

Realtime Firestore query results in error for "docChanges" #824

Thkasis opened this issue May 15, 2018 · 11 comments

Comments

@Thkasis
Copy link

Thkasis commented May 15, 2018

[REQUIRED] Describe your environment

  • Operating System version: Windows, Google Chrome
  • Firebase SDK version: 5.0.1
  • Firebase Product: Firestore

Simple query for realtime onSnapshot() results in error when trying to work with snapshot.docChanges.
I don't see any doc.docChanges defined as it was in the previous version (4.9.1) that I was using and I get this error:
snapshot.docChanges.forEach is not a function. Logging snapshot.docChanges is not an array of changes as it was before and instead shows the prototype method.

Steps to reproduce:

Simply query data either using get() or realtime onSnapshot() similar to Firestore documents.

For realtime query:

firebase.firestore(firebase.app("ProjectFirst")).collection('test').where("flg", "==", "i").onSnapshot(function(snapshot) {
//there is data in database and I see them using get() method for instance
snapshot.docChanges.forEach(function(change) {
...
});
});

when I log snapshot.docChanges I see this instead of the array of results :

ƒ (e){validateOptionNames("QuerySnapshot.docChanges",e,["includeMetadataChanges"]),e&&validateNamedOptionalType("QuerySnapshot.docChanges","boolean","includeMetadataChanges",e.includeMetadataChanges);v…

@mikelehen
Copy link
Contributor

@Thkasis Sorry for the trouble! We changed docChanges into a method in 5.0.0 so you must now do snapshot.docChanges() instead of snapshot.docChanges. You can find more details in our release notes here: https://firebase.google.com/support/release-notes/js#5.0.0

Thanks and sorry!

@Thkasis
Copy link
Author

Thkasis commented May 16, 2018

@mikelehen, not a problem, thanks for the update. It would definitely be helpful to have this in the documentation instead if it's supposed to be the standard from now on as documentation still shows docChanges.forEach()

Thanks for all the good work.
Cheers

@mikelehen
Copy link
Contributor

Thank you! I see that indeed https://firebase.google.com/docs/firestore/query-data/listen still has the old syntax. Whoops! We'll get that updated shortly. Thanks for mentioning it.

@samtstern
Copy link
Contributor

@Thkasis updating the docs right now, thanks!

@mohshraim
Copy link

@mikelehen
As this discuss the documentation i suggest also to add the new feature
.get({source:'cache'})
.get({source:'server'})

@samtstern
Copy link
Contributor

@mohshraim yep we will add this to the docs soon, sorry about the delay!

@myleftshoe
Copy link

@google-cloud/firestore 0.16.1 has the opposite problem - snapshot.docChanges() errors with docChanges is not a function so I'm using snapshot.docChanges instead!

@mikelehen
Copy link
Contributor

cc/ @schmidt-sebastian

@schmidt-sebastian
Copy link
Contributor

PR for @google-cloud/firestore pending: googleapis/nodejs-firestore#324

This will make docChanges() a method in all of our JavaScript-based SDKs.

@elchefuser
Copy link

it seems they came back to a property , for me just works like docChanges, without parenthesis

@mikelehen
Copy link
Contributor

@elchefuser It should still be a method. Which npm module are you using and what version?

@firebase firebase locked and limited conversation to collaborators Oct 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants