简体   繁体   English

Firebase 按字段对集合进行排序

[英]Firebase sort collection by field

I have a FireBase Collection ('Messages'):我有一个 FireBase 集合(“消息”):

在此处输入图片说明

I want to sort the collection by specifiec field ('timeStamp').我想按特定字段('timeStamp')对集合进行排序。

  1. How can I sort it by timeStamp?如何按时间戳对其进行排序?
  2. Is there any way to sort the docs by timeStamp on Firebase instead of sort it while getting snapshot有什么方法可以在 Firebase 上按时间戳对文档进行排序,而不是在获取快照时对其进行排序

You should definitely read the documentation on ordering query results .您绝对应该阅读有关订购查询结果文档 Use the orderBy method to specify which field should be sorted.使用orderBy方法指定应该对哪个字段进行排序。

firestore.collection("messages").orderBy("timeStamp")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM