在 Firebase Firestore 中,我想使用 orderBy 两次。我是否需要创建索引来加速查询?
例如:
Query query = fsDB.collection("users").document(currentUID).collection("received_messages")
.orderBy("messageSeen").orderBy("date");
没有像使用范围或“where”时那样显示的自动错误消息。
结构如下:
received_messages
date: 01/02/99
messageSeen: true
from: keuajopdf315
我应该在集合“收到的消息”和“messageSeen”和“日期”字段上放置索引以加快查询速度吗?
当我尝试使用两个 orderBy() 子句运行查询时,出现错误:
查询需要索引。您可以在此处创建它:...
添加错误消息中链接的索引后,我可以检索按状态然后按索引排序的文档。在此处查看我的工作 jsbin:https ://jsbin.com/rewujav/edit ? js,console
docs.orderBy("state").orderBy("index").get().then(function(snapshot) {
snapshot.forEach((doc) => {
console.log(doc.id+": state="+doc.data().state+" index="+doc.data().index);
})
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句