javascript - 调用 Firestore Collection 时如何使用 orderBy?

标签 javascript angular google-cloud-firestore

我正在使用 [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/

相关文章:

javascript - *ngFor 使用异步管道进行本地分配并减少订阅数量

firebase - Flutter firestore:使用 'where'和DISTINCT文档字段查询文档

javascript - 无法从子状态正确初始化父组件中的状态

javascript - 为什么 jQuery 更改事件不适用于选择选项?

Angular 2 最终版本 - ngModule 无法识别共享组件

typescript - angular 2自定义指令OnInit

javascript - picnet 表过滤器不适用于动态表

javascript - JS 函数正在破坏剩余的函数

firebase - 在同一字段上存储多个查询

dart - 将字符串从 firestore 保存到变量