我正在尝试根据messageUpdatedAt
字段(时间戳)获得一组有序的结果。
尝试了以下代码。
firebase
.firestore()
.collection('conversations')
.where('type', '==', 'direct')
.where('ids', 'array-contains', id)
.orderBy('messageUpdatedAt', 'DESC')
.limit(limit)
如果运行此命令,则会得到无序的结果集。但是,如果我评论包含where
的杂音条件(where('ids', 'array-contains', id)
),则结果是有序的(基于messageUpdatedAt
字段)。
在复合索引下面添加到集合conversation
中。
type - Ascending
ids - Array
messageUpdatedAt - Descending
我做错什么了吗?无论如何,都可以运行此程序而无需注释,并获得有序的结果集(基于messageUpdatedAt
字段)。
答案 0 :(得分:0)
对我来说,某些文档的orderBy字段为undefined
,而某些文档没有该字段。这阻止了文件的订购。我通过提供默认值(Unix纪元时间)更新了这些字段,并按顺序获取了文档。