javascript - Select last n records by key in firestore? - Stack Overflow

How does one select the last n items in a collection in firestore?I'm considering migrating a ne

How does one select the last n items in a collection in firestore? I'm considering migrating a new project from the real time database to firestore. In the realtime database, I used the below code:

ref.orderByKey().limitToLast(n);

I've reviewed the docs at , and they don't appear to mention how to achieve this in firestore. I suppose I could add a timestamp field to every element of the collection and then order by descending timestamp, but I think there should be an easier way to acplish this.

How does one select the last n items in a collection in firestore? I'm considering migrating a new project from the real time database to firestore. In the realtime database, I used the below code:

ref.orderByKey().limitToLast(n);

I've reviewed the docs at https://cloud.google./firestore/docs/query-data/order-limit-data, and they don't appear to mention how to achieve this in firestore. I suppose I could add a timestamp field to every element of the collection and then order by descending timestamp, but I think there should be an easier way to acplish this.

Share Improve this question edited Oct 8, 2017 at 22:34 Frank van Puffelen 601k85 gold badges890 silver badges860 bronze badges asked Oct 8, 2017 at 19:50 John AnglandJohn Angland 4564 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

In the Firebase Realtime Database there was the concept of a push ID, which was a key that was automatically chronologically ordered. This made ordering nodes chronologically in a query as easy as you've shown.

In Cloud Firestore there is no built-in metadata for when a document was added, or when it was last updated. If you want to build queried based on such metadata, you will have to set the corresponding properties on the documents yourself.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745347807a4623644.html

相关推荐

  • javascript - Select last n records by key in firestore? - Stack Overflow

    How does one select the last n items in a collection in firestore?I'm considering migrating a ne

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信