0

I am working on an Angular (version 9.1.13) project where I am using Firestore , Fire version ("@angular/fire": "^6.1.5") , Firebase version ("firebase": "^8.10.1") for the database. I am trying to fetch data from Firestore using a query with where, orderBy, and limit methods. Here's my code:

const ref: CollectionReference = this.firestore.collection(this.path()).ref;
let query: Query = collectionRef
        .where(...conditions...)
        .where(...conditions...)
        .orderBy('time', 'desc')
        .limit(5);

this.subscription = query.snapshotChanges().subscribe((changes) => {}

But I am getting the error at query.snapshotChanges line saying - Property snapshotChanges does not exist on type Query

My questions -

  1. How can I correctly use snapshotChanges() for real-time updates with a filtered and ordered query in AngularFirestore?
  2. Is upgrading Firestore a viable solution for this issue?

1 Answer 1

0

The snapshotChanges() observable is specific to the AngularFire library.

The code you have seems to be using the regular Firebase SDK for JavaScript though, which doesn't have snapshotChanges() but rather has a method onSnapshot for listening for changes.

You'll have to decide whether you want to use AngularFire, or (only) use the JavaScript SDK and then stick to the APIs offered by that SDK/library.

Sign up to request clarification or add additional context in comments.

3 Comments

Can you provide an example of how to implement onSnapshot with proper unsubscribe logic for my query? I tried to use unsubscribe from onSnapshot but it doesn't work that is why I started using snapshotchanges.
See github.com/angular/angularfire/blob/master/docs/compat/…. Just use snapshotChanges() instead of valueChanges.
stackoverflow.com/questions/78279465/… I tried the approach using rxjs it worked as required but I am facing this issue could you help me with this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.