首页 > 解决方案 > 我不断收到错误消息:错误:提供给 Query.startAt() 的参数过多。使用 AngularFire2 时

问题描述

我有一个接受参数并返回数据集的简单函数

search(searchValues , numOfItems, startKey?) {
    return this.db.collection('gppContract', ref => ref
    .where('financialYear', '==', searchValues.financialYear)
    .startAt(startKey)
    .orderBy('amount', 'desc')
    .limit(numOfItems + 1))
      .valueChanges();


  }

我做错了什么或错过了什么?我在这里不知所措。

标签: angularfirebaseangularfire2

解决方案


首先,orderBy()需要before startAt(),要知道结果应该是根据哪个节点。

其次,orderBy()只接受一个参数,它应该与where()来自文档的字段相同:

范围过滤器和 orderBy 应该在相同的字段上:

citiesRef.where("population", ">", 100000).orderBy("population")

检查这个:

https://github.com/angular/angularfire2/blob/master/docs/firestore/querying-collections.md


推荐阅读