Firestore:如何按数组对象的字段使用顺序

时间:2018-09-27 10:32:04

标签: firebase google-cloud-firestore

我有一个这样的数据库。

enter image description here

如何按数组中的时间戳字段排序?

.orderBy("received[0].timestamp", "desc")

1 个答案:

答案 0 :(得分:2)

您不能直接。但是您可以做的是在文档上创建一个名为firstTimestamp或类似名称的新字段,然后将时间戳记从数组的第一个元素复制到该字段中。您可以在Cloud Function或前端/后端代码中执行此操作。这样,您可以按该字段进行排序或过滤。