Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.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 云FireStore:NativeFirebaseError:[FireStore/失败的前提条件]查询需要索引。?_Javascript_Firebase_React Native_Google Cloud Firestore - Fatal编程技术网

Javascript 云FireStore:NativeFirebaseError:[FireStore/失败的前提条件]查询需要索引。?

Javascript 云FireStore:NativeFirebaseError:[FireStore/失败的前提条件]查询需要索引。?,javascript,firebase,react-native,google-cloud-firestore,Javascript,Firebase,React Native,Google Cloud Firestore,我试图从firestore获取数据,但出现错误。 我有两个条件,一个条件是userid,另一个条件是获取最近7天的数据 getReportData = (callBack) => { var query = firestore().collection("booking") query = query.where("docId", "==", firebase.auth().currentUser.uid) const currentTime = new Date(); var d =

我试图从firestore获取数据,但出现错误。 我有两个条件,一个条件是userid,另一个条件是获取最近7天的数据

getReportData = (callBack) => {

var query = firestore().collection("booking")
query = query.where("docId", "==", firebase.auth().currentUser.uid)
const currentTime = new Date();
var d = new Date();
d.setDate(d.getDate() - 8);

query = query.where("createdAt", ">=", d);

query.get().then((doc) => {
  const list = [];
  doc.forEach(function (docV) {
    list.push(docV.data());
  });
  console.log("data" , list);
  console.log("data length" , list.length);
}).catch(function (error) {
  console.log('booking error', error);

})
}

这给了我错误

NativeFirebaseError: [firestore/failed-precondition] The query requires an index. You can create it here

错误中说明了一切,您需要一个索引来执行此查询

Firebase在这里帮助很大,因为它甚至为您提供了直接创建索引的链接。您只需按照链接创建正确的索引,查询即可工作;)