Search code examples
javascriptfirebasefirebase-realtime-databasegoogle-cloud-firestoreangularfire2

Firestore - OrderBy won't work if placed inside return code


I want to order my data by "Time", but whenever i try to add .orderby("time"), it displays an error.

My Get function"

return this.firestore.collection('East_Area').snapshotChanges();

I tried doing this:

return this.firestore.collection('East_Area').orderBy("time").limit(3).snapshotChanges();

Am i doing something wrong? Any help would be appreciated!


Solution

  • Change this:

    return this.firestore.collection('East_Area').orderBy("time").limit(3).snapshotChanges();
    

    into this:

    do this then: return this.firestore.collection('East_Area', ref => ref.orderBy("time")).snapshotChanges()
    
    

    snapshotChanges() is a method inside angulareFire but you are using plain javascript, therefore you need to use get() method to retrieve data.