Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firebase错误-为Query.startAt()提供的参数太多_Javascript_Firebase_Google Cloud Firestore - Fatal编程技术网

Javascript Firebase错误-为Query.startAt()提供的参数太多

Javascript Firebase错误-为Query.startAt()提供的参数太多,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,我想弄明白为什么我会犯这个错误 FirebaseError:为Query.startAt()提供的参数太多。参数的数量必须小于或等于Query.orderBy()子句的数量 使用此代码: const query = firebase .getDatabase() .collection("users") .where("premium", "==", true) // get premium users .where(&

我想弄明白为什么我会犯这个错误

FirebaseError:为Query.startAt()提供的参数太多。参数的数量必须小于或等于Query.orderBy()子句的数量

使用此代码:

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) => {
          ...
    );
正如你所看到的,我正试图获得那些发布了一些音乐的高级用户。我使用的是where和startAt子句,而不是orderBy

我做错了什么


谢谢

仔细阅读错误消息:

参数的数量必须小于或等于Query.orderBy()子句的数量

您的代码根本不显示任何orderBy子句,因此本例中的数字为0。但是您为
startAt()
提供了一个参数。具体来说,您应该提供一个orderBy子句。它必须与范围查询的字段匹配:

const query = firebase
  .getDatabase()
  .collection("users")
  .where("premium", "==", true) // get premium users
  .where("totalPosts", ">", 0)  // that have posted some music
  .orderBy("totalPosts")
然后,您的分页应该重复完全相同的查询,只是这次使用startAt告诉它在哪里取:

return query.startAt(0);

为什么必须在startAt之前使用orderBy?因为不平等或者为什么?我的意思是,在第一个时刻,我认为使用我的第一个代码,我可以使用startAt在一些文档中为自己编制索引,但事实并非如此。分页查询需要了解文档的顺序,以便每个页面对同一系列查询使用相同的顺序。Firestore不会猜到你想要的订单。