I have the following change stream but it does not function changed is not logged once I update using mongo compass.
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)
}
Is the problem that you don't normally update the _id of a document in a collection? If, for some reason, you are updating the _id then maybe the problem is in how you're referencing your $match. This works for me: