Angular Firestore 按时间戳值对文档进行排序

Cyb*_*ker 3 javascript firebase firebase-realtime-database angular google-cloud-firestore

我有一个问题,希望有人能回答,因为我已经花了两天时间尝试解决它,但完全没有运气。

我有一系列文件,到目前为止还不错..

每个文档都有一个字段“preferred_time”,其中包含时间戳作为值。

是否可以使用该值作为参考对集合内的文档进行排序?

我试过:

 return this.afs.collection('viewings', ref => 
    ref.orderBy('preferred_time')
    );
Run Code Online (Sandbox Code Playgroud)

但它似乎不适用于时间戳字段类型。

请帮忙!!

谢谢,M。

Jed*_*edi 5

您可以按降序或升序对首选时间进行排序。在这里阅读更多信息: https ://firebase.google.com/docs/firestore/query-data/order-limit-data

 return this.afs.collection('viewings', ref => 
ref.orderBy('preferred_time','desc'))
);
Run Code Online (Sandbox Code Playgroud)