Ad

How To Order Query From Firestore Based On Timestamp In Ionic 4

I've performed a query to Firebase firestore and the data is being called perfectly. but I can't use any kind of ordering on this query.

here is my code:

   this.dressCollection = db.collection<Dress>('dress').orderBy("date", Query.Direction.ASCENDING);
    this.dress = this.dressCollection.snapshotChanges().pipe(
      map(actions => {
        return actions.map(a => {
          const data = a.payload.doc.data();
          const id = a.payload.doc.id;
          return { id, ...data };
        });
      })
    );

I get this 2 errors:

Property 'orderBy' does not exist on type 'AngularFirestoreCollection<Dress>'

and

Cannot find name 'Query'

Ad

Answer

Use

, 'date',ref=>ref.orderBy('date','asc')

inside the collection

Ad
source: stackoverflow.com
Ad