How to watch for changes to specific fields in MongoDB change stream

后端 未结 2 994
没有蜡笔的小新
没有蜡笔的小新 2021-02-08 19:46

I am using the node driver for mongodb to initiate a change stream on a document that has lots of fields that update continuously (via some logic on the insert/update end that c

2条回答
  •  粉色の甜心
    2021-02-08 20:26

    I'm looking for something similar, but from the blog post at https://www.mongodb.com/blog/post/an-introduction-to-change-streams, it looks like you might need to change your filter to:

    var filter = {
        $match: {
            $and: [
                { "updateDescription.updatedFields.SomeFieldA": { $exists: true } },
                { operationType: 'update'}
            ]
        }
    };
    

提交回复
热议问题