0

I would like to watch the change stream of a collection, but filter it by operationType (insert, delete) and some fields.

collection.watch(
    [{
        $match: { 'fullDocument.name': 'Dave' } /*{
            $and: [ { 'fullDocument.name': 'Dave' }, { $or: [ { 'operationType': 'insert' }, { 'operationType': 'delete' } ] } ]
        }*/
    }]
).on('change', result => {
    console.log(result);
});

I tried the above without success. When I add $match: { 'fullDocument.name': 'Dave' } as aggregation, it only returns insert events. When I take the commented solution, it returns again insert only.

How do I watch for insert, delete and document fields?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.