Firebase 9上的复合查询(模块化)



我有一个Expo项目,需要进行以下查询:

const queryEvents = query(
colRef,
where('neighborhood', 'in', neighbors),
where('curfew', '<', end)
);

其中"neighbors"是地理哈希数组,"end"是时间戳。到目前为止,在第一个条件下,它运行良好,但每当我放入第二个条件时,firebase就会抛出以下错误:

@firebase/firestore:,firestore(9.9.2(:快照侦听器中未捕获错误:,{"代码":"失败的前提条件","名称":"FirebaseError"}

就我所读到的内容而言,使用不同的运算符查询不同的字段有一些限制,但在文档中,有一个"有效范围"查询的例子,但这个例子只是两个不同的查询,因为我对firestore/firebase还很陌生,所以我想知道"q1"one_answers"q2"是否可以在onSnapshot调用中使用。下面是给定的例子:

import { query, where } from "firebase/firestore";  
const q1 = query(citiesRef, where("state", ">=", "CA"), where("state", "<=", "IN"));
const q2 = query(citiesRef, where("state", "==", "CA"), where("population", ">", 1000000));

根据评论建议,以下是快照:

const getEvents = async (dbx) => {

let end = new Date(Date.now() + ( 3600 * 1000 * 25 ));
console.log("Date: ", end)
const colRef = collection(dbx, 'events');
const queryEvents = query(colRef, where('neighborhood', 'in', neighbors));
onSnapshot(queryEvents, 
(snapshot)=>{
let evs = [];
snapshot.docs.forEach((doc)=>{
evs.push({...doc.data(), key: doc.id})
})
setEvents(evs)
return evs;
});
}
Per another contributor's request, here's the package.json:
{
"name": "cartelera",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"@react-native-async-storage/async-storage": "~1.17.3",
"@react-native-firebase/app": "^15.3.0",
"@react-native-firebase/firestore": "^15.3.0",
"@react-native-firebase/storage": "^15.3.0",
"@react-navigation/bottom-tabs": "^6.3.2",
"@react-navigation/drawer": "^6.4.3",
"@react-navigation/native": "^6.0.11",
"@react-navigation/native-stack": "^6.7.0",
"expo": "~45.0.0",
"expo-location": "~14.2.2",
"expo-status-bar": "~1.3.0",
"firebase": "^9.9.2",
"formik": "^2.2.9",
"geofire": "^6.0.0",
"geohashes-near": "^2.0.1",
"moment": "^2.29.4",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "0.68.2",
"react-native-elements": "^3.4.2",
"react-native-gesture-handler": "~2.2.1",
"react-native-reanimated": "~2.8.0",
"react-native-safe-area-context": "4.2.4",
"react-native-screens": "~3.11.1",
"react-native-vector-icons": ">= 6.x.x",
"react-native-web": "0.17.7"
},
"devDependencies": {
"@babel/core": "^7.18.10"
},
"private": true,
"react-native-dynamic-vector-icons": "WrathChaos/react-native-dynamic-vector-icons#expo"

}

事实证明,复合索引错误确实是问题所在,我没有得到设置它的链接。我确实在谷歌上联系了支持人员,但他们也没有得到答复。我采取了卸载和重新安装Firestore的方法,但直到我卸载并重新安装Firebase,这才奏效,然而,如果我只执行

%yarn add firebase

%npm install firebase

还不够,我不得不用来表现

% npm install firebase@9.6.11

完成后,我重新启动了该项目,构建复合索引的链接出现了,现在一切都很好。

最新更新