[英]Mongodb Stitch realtime watch
What I intend to achieve is some sort of "live query" functionality.我打算实现的是某种“实时查询”功能。 So far I've tried using the "watch" method.
到目前为止,我已经尝试过使用“watch”方法。 According to the documentation :
根据文档:
You can open a stream of changes that match a filter by calling collection.watch(delegate:) with a $match expression as the argument.
您可以通过使用 $match 表达式作为参数调用 collection.watch(delegate:) 来打开与过滤器匹配的更改流。 Whenever the watched collection changes and the ChangeEvent matches the provided $match expression, the stream's event handler fires with the ChangeEvent object as its only argument
每当被监视的集合发生变化并且 ChangeEvent 匹配提供的 $match 表达式时,流的事件处理程序就会以 ChangeEvent 对象作为其唯一参数触发
Passing the doc ids as an array works perfectly, but passing a query doesn't work:将 doc id 作为数组传递非常有效,但传递查询不起作用:
this.stitch.db.collection<Queue>('queues')
.watch({
hospitalId: this.activehospitalid
}));
I've also tried this:我也试过这个:
this.stitch.db.collection<Queue>('queues')
.watch({
$match: {
hospitalId: this.activehospitalid
}
},
));
Which throws an error on the console "StitchServiceError: mongodb watch: filter is invalid (unknown top level operator: $match)".这会在控制台上引发错误“StitchServiceError: mongodb watch: filter is invalid (unknown top level operator: $match)”。 The intention is watch all documents where the field "hospitalId" matches the provided value, or to effectively pass a query filter to the
watch()
method.目的是监视字段“hospitalId”与提供的值匹配的所有文档,或者有效地将查询过滤器传递给
watch()
方法。
After a long search I found that it's possible to filter, but the query needs to be formatted differently经过长时间的搜索,我发现可以进行过滤,但查询需要采用不同的格式
this.stitch.db.collection<Queue>('queues')
.watch({
$or: [
{
"fullDocument.hospitalId": this.activehospitalid
}
]
},
));
For anyone else who might need this, please note the important fullDocument part of the query.对于可能需要此功能的任何其他人,请注意查询的重要fullDocument部分。 I havent found much documentation relating to this, but I hope it helps
我还没有找到很多与此相关的文档,但我希望它有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.