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 badges1 Answer
Reset to default 8Read 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);