我有以下更改流,但它的功能没有更改,一旦我使用芒果罗盘进行更新,就不会记录更改。
var pipeline = [
{ $match: { _id: ObjectId(id) } }
];
try {
const collection = client.db("mydb").collection("shop");
const changeStream = collection.watch(pipeline);
changeStream.on('change', (next) => {
//console.log(next);
console.log('changed')
}, err => {
console.log(err);
});
} catch (err) {
console.log(err)
}发布于 2022-02-16 14:14:13
您通常不会更新集合中文档的_id,这是一个问题吗?如果由于某种原因,您正在更新_id,那么问题可能在于如何引用您的$match。这对我来说很管用:
const pipeline01 = [
{ $match: { 'updateDescription.updatedFields.fieldIamInterestedIn': { $ne: undefined } } },
{ $project: { 'fullDocument._id': 1, 'fullDocument.anotherFieldIamInterestedIn': 1 } },
];
theCollectionIamWatching.watch(pipeline01, { fullDocument: 'updateLookup' }).on('change', async (data) => {
// do the thing I want to do using data.fullDocument
});https://stackoverflow.com/questions/65086081
复制相似问题