问题描述
我想实时跟踪半径范围内的用户。我有一个Firestore集合文档,其字段userId
与我的userId不同。
这是代码
this.watch = Plugins.Geolocation.watchPosition(
{ maximumAge: 0,timeout: 5000 },(geoPosition) => {
if (geoPosition) {
console.log(geoPosition);
const field = "position";
const center = this.geo.point(
geoPosition.coords.latitude,geoPosition.coords.longitude
);
const usersRef = this.afs.firestore.collection('users');
const nearbyusers = usersRef.where('userId','!=',this.uid).orderBy('userId');
const position = this.geo.point(
geoPosition.coords.latitude,geoPosition.coords.longitude
);
usersRef.doc(this.uid).set({ position },{ merge: true });
this.points = this.radius.pipe(
switchMap((r) => {
return this.geo.query(nearbyusers).within(center,r,field,{log: true});
}),shareReplay(1)
);
}
}
);
在我的用户集中,我有两个文档。但是运行这段代码后,我什么也没得到。 没错。
解决方法
我认为您应该尝试这样做:
不支持带有!=子句的查询。在这种情况下,将 查询分为大于查询和小于查询。例如, 尽管不支持查询子句where(“ age”,“!=”,“ 30”), 您可以通过组合两个查询来获得相同的结果集,其中一个与 子句where(“ age”,“ ”,30)Read more
对您来说,将是这样:
...
const nearbyusers = usersRef
.where('userId','<',this.uid)
.where('userId','>',this.uid)
.orderBy('userId')
...