我有一个世博会项目,在这里我需要执行以下查询:
const queryEvents = query(
colRef,
where('neighborhood', 'in', neighbors),
where('curfew', '<', end)
);其中‘邻居’是一个地杂凑数组,'end‘是一个时间戳。到目前为止,对于第一个条件,它可以正常工作,但是每当我输入第二个条件时,firebase就会抛出这个错误:
@firebase/ Firestore :,Firestore (9.9.2):快照侦听器中的未明错误:,{“代码”:“失败-前提条件”,“名称”:“FirebaseError”}
就我所读到的内容而言,在使用不同运算符查询不同字段方面存在一些限制,然而在文档中有一个“有效范围”查询的示例,但这样的示例只是两个不同的查询,因为我对q2/firebase非常陌生,所以我想知道'q2‘和’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"}
发布于 2022-09-16 16:31:52
事实证明,综合索引错误确实是问题所在,我没有得到设置它的链接。我在谷歌上确实提供了联系支持,但他们也没有任何答案。我求助于卸载和重新安装Firestore,但直到我卸载和重新安装Firebase时才起作用,但如果我只执行
%yarn add firebase的
%npm install firebase还不够,我不得不用得很有表情
% npm install firebase@9.6.11完成之后,我重新启动了这个项目,构建综合索引的链接出现了,现在一切都很好。
https://stackoverflow.com/questions/73481036
复制相似问题