[英]mongodb changestream "pipeline" not working
I have some code that watches a mongodb collection for updates... I have it setup so that when anyone sends a message, the changestream will detect that... The issue is that when I try to add a pipeline, the updates do not get detected...我有一些代码可以监视 mongodb 集合的更新......我已经设置好了,这样当任何人发送消息时,变更流都会检测到......问题是当我尝试添加管道时,更新不会被发现...
Here are some things that I've tried:以下是我尝试过的一些事情:
const pipeline = [
{ $match: { 'fullDocument.username_pair': 'HardCodedUsernameInDatabase' }}
];
changeStream = message_collection.watch(pipeline);
and和
const pipeline = [
{ $match: { username_pair: 'HardCodedUsernameInDatabase' }}
];
changeStream = message_collection.watch(pipeline);
again, the code will detect all messages in the absence of any pipeline, ie:同样,代码将在没有任何管道的情况下检测所有消息,即:
changeStream = message_collection.watch();
... ...
UPDATE:更新:
The reason why this is tricky is because the document I'm listening to looks like this:这很棘手的原因是因为我正在听的文件是这样的:
_id:some_id
username_pair:"Test1234test1111"
messages:Array
The username_pair never updates, the messages array is what updates... I need to be looking at the document matching the username_pair, and I need to detect changes in the messages array that corresponds to the username_pair. username_pair 永远不会更新,messages 数组是什么更新...我需要查看与 username_pair 匹配的文档,我需要检测与 username_pair 对应的消息数组中的更改。
I guess the trick is to add option called fullDocument
while opening the change stream on collection.我想诀窍是在打开集合上的更改流时添加名为
fullDocument
选项。 see here看这里
someCollection.watch([{
"$match": {
"operationType": {
"$in": ["update"]
},
"fullDocument.username_pair": "HardCodedUsernameInDatabase"
}
}], {"fullDocument": "updateLookup"})
Hope this helps希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.