最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firebase Error - Too many arguments provided to Query.startAt() - Stack Overflow

programmeradmin2浏览0评论

I am trying to figurate why am I getting this error

FirebaseError: Too many arguments provided to Query.startAt(). The number of arguments must be less than or equal to the number of Query.orderBy() clauses

with this code:

const query = firebase
  .getDatabase()
  .collection("users")
  .where("premium", "==", true) // get premium users
  .where("totalPosts", ">", 0); // that have posted some music


...

return query
    .startAt(0)
    .limit(1)
    .get()
    .then((snapshot) => {
          ...
    );

As you can see, I am trying to get premium users that have posted some music. I am using the where and startAt clause, and not the orderBy.

What am I doing wrong?

Thanks!

I am trying to figurate why am I getting this error

FirebaseError: Too many arguments provided to Query.startAt(). The number of arguments must be less than or equal to the number of Query.orderBy() clauses

with this code:

const query = firebase
  .getDatabase()
  .collection("users")
  .where("premium", "==", true) // get premium users
  .where("totalPosts", ">", 0); // that have posted some music


...

return query
    .startAt(0)
    .limit(1)
    .get()
    .then((snapshot) => {
          ...
    );

As you can see, I am trying to get premium users that have posted some music. I am using the where and startAt clause, and not the orderBy.

What am I doing wrong?

Thanks!

Share Improve this question asked Oct 4, 2020 at 19:33 Conchi BermejoConchi Bermejo 3532 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Read the error message carefully:

The number of arguments must be less than or equal to the number of Query.orderBy() clauses

Your code doesn't show any orderBy clauses at all, so the number in this case is 0. But you provide 1 argument to startAt(). You should actually provide an orderBy clause, to be specific. It must match the field of your range query:

const query = firebase
  .getDatabase()
  .collection("users")
  .where("premium", "==", true) // get premium users
  .where("totalPosts", ">", 0)  // that have posted some music
  .orderBy("totalPosts")

Then, your pagination should repeat the exact same query, only this time with startAt to tell it where to pick up:

return query.startAt(0);
发布评论

评论列表(0)

  1. 暂无评论