【发布时间】:2019-05-01 23:41:23
【问题描述】:
我尝试从我的 Firestore 中获取文档并按时间戳对其进行排序。时间戳实际上是“firebase 格式”(见下文)
代码
我尝试使用此代码
const querySnapshot = await db
.collection("placeVisits")
.where("placeId", "==", req.params.placeId)
.orderBy("time", "desc")
.get();
但它会产生
error: (node:8356) UnhandledPromiseRejectionWarning: Error: 9 FAILED_PRECONDITION: The query requires an index. You can create it here: https://console.firebase.google.com/...
但是,这可以正常工作(当然不能排序)
const querySnapshot = await db
.collection("placeVisits")
.where("placeId", "==", req.params.placeId)
.get();
我不知道如何解决此问题或发生此问题的原因。是因为 Firestore 快照不可排序还是什么?
【问题讨论】:
标签: javascript node.js firebase google-cloud-firestore