我正在使用 [Firestore 文档][1]。如果我省略 .orderBy
,查询会返回数据,但当我包含它时,则没有数据。
async getAccounts() {
return await this.db
.collection("mas-accounts")
.get()
.orderBy("names.givenName")
.then(querySnapshot => {
querySnapshot.forEach(doc => {
doc = doc.data();
console.log(doc);
});
});
}
没有排序的结果示例:
names: {familyName: "Doe", givenName: "John"}
relations: {person: "Junior Blanks", type: "child"}
最佳答案
根据您的评论:
the vs code emmet gives a .orderBy option on .get() and on .collection() and the console does not give an error it just returns an empty promise.
解决这个问题的方法是在调用get()
之前添加对.orderBy("names.givenName")
函数的调用。
关于javascript - 调用 Firestore Collection 时如何使用 orderBy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54399795/