Javascript 当我使用查询运算符时,Firestore运行了两次查询,第二次得到null作为响应
我想从firestore获取集合(“邀请”)中的所有文档,其中日期等于或大于今天00:00:00以及其他一些参数 我的职能是:Javascript 当我使用查询运算符时,Firestore运行了两次查询,第二次得到null作为响应,javascript,firebase,react-native,date,google-cloud-firestore,Javascript,Firebase,React Native,Date,Google Cloud Firestore,我想从firestore获取集合(“邀请”)中的所有文档,其中日期等于或大于今天00:00:00以及其他一些参数 我的职能是: var today_init = new Date() today_init.setHours(0, 0, 0, 0) let query = await db.collection("invitations") .where("date", ">=", today_init) .where(&
var today_init = new Date()
today_init.setHours(0, 0, 0, 0)
let query = await db.collection("invitations")
.where("date", ">=", today_init)
.where("sender.user_uid", "==", Fire.user.uid)
.where('data.is_here', '==', false)
query.onSnapshot(async (querySnapshot) => {
try {
console.log(querySnapshot)
//more code here....
}catch(error){
console.log(error)
}
它会自动运行两次,第一次执行返回我想要的firestore文档,下一次执行返回null:
很明显,第一个响应就是我想要的,但是我不知道为什么会运行两次,或者到底发生了什么,但是空值破坏了我的逻辑
当我评论这句话时:
.where("date", ">=", today_init)
查询运行得很好。我的想法是我不想要旧的请帖
另外,我正在使用react native过了一段时间,我想到了这个:
await db.collection("invitations")
.where("date", ">", today_init)
.where("sender.user_uid", "==", Fire.user.uid)
.where("data.is_here", "==", false)
.orderBy("date", "desc")
.onSnapshot((querySnapshot) => {
console.log(querySnapshot)
}, function (error) {
console.log(error)
})
错误回调函数帮助我创建索引
更多信息: