【发布时间】:2022-01-17 09:42:40
【问题描述】:
我想提出一个过滤属性的请求。 我知道使用 firebase ,我们不能将 where 条件与多个不同的字段一起使用,或者将 Where 与字段属性 A 一起使用并按属性 B 排序。所以我使用索引进行测试。
我为一个集合创建一个索引
数据库
收藏:地理位置
数据示例:
{
date: 1638926138,
localisation: { latitude: 48.120599, longitude: 2.0256055 },
po: 1251653A,
st: pQN8,
user: OeS2
}
我创建一个索引:
Id collection: geo
fields index : date => descending, localisation.latitude => ascending
status : activate
请求:
import firestore from "@react-native-firebase/firestore";
firestore()
.collection(COLLECTION)
.where("localisation.latitude", ">=", lat_min)
.where("localisation.latitude", "<=", lat_max)
.get()
.then(querySnapshot => {})
没关系(但我想将我的索引与字段“日期”一起使用)
import firestore from "@react-native-firebase/firestore";
firestore()
.collection(COLLECTION)
.where("localisation.latitude", ">=", lat_min)
.where("localisation.latitude", "<=", lat_max)
.orderBy('date')
.get()
.then(querySnapshot => {})
错误
可能的未处理承诺拒绝(id:0):
错误:firebase.firestore().collection().orderBy() 查询无效。初始 Query.orderBy() 参数:日期必须与 Query.where() fieldPath 参数相同:调用不等式运算符时的 localisation.latitude
感谢您的帮助!
解决
哦,它的工作谢谢 只是现在 如果我会用这个请求进行测试
firestore()
.collection(COLLECTION)
.orderBy("localisation.latitude")
.where("localisation.latitude", ">=", lat_min)
.where("localisation.latitude", "<=", lat_max)
.orderBy('date', 'desc')
.get()
索引宽度:
localisation.latitude => ascending
date => descending
但我用 localisation.longitude 测试
其他测试
我的索引:
localisation.latitude => ascending
localisation.longitude => ascending
date => descending
我的请求
firestore()
.collection(COLLECTION)
.orderBy("localisation.latitude")
.where("localisation.latitude", ">=", lat_min)
.where("localisation.latitude", "<=", lat_max)
.orderBy("localisation.longitude")
.where("localisation.longitude", ">=", lon_min)
.where("localisation.longitude", "<=", lon_max)
.orderBy('date', 'desc')
没用
错误
Possible Unhandled Promise Rejection (id: 0):
Error: firebase.firestore().collection().where() Invalid query. All where filters with an inequality (<, <=, >, != or >=) must be on the same field. But you have inequality filters on 'localisation.latitude' and 'localisation.longitude'
【问题讨论】:
标签: javascript firebase react-native google-cloud-firestore