如何在mongodb和nodejs中使用聚合监视集合的插入和删除?

如何在mongodb和nodejs中使用聚合监视集合的插入和删除?,mongodb,mongodb-query,aggregation-framework,Mongodb,Mongodb Query,Aggregation Framework,我想删除集合的名称,但按operationType(insert,delete)和一些字段对其进行筛选 let collection = client.db('testdb').collection('test'); 这将返回所有 这将只返回insert collection.watch( [{ $match: { 'fullDocument.name': 'Tom' } }] ).on('change', result => { console.

我想删除集合的名称,但按
operationType
insert
delete
)和一些字段对其进行筛选

let collection = client.db('testdb').collection('test');
这将返回所有

这将只返回insert

collection.watch(
    [{
        $match: { 'fullDocument.name': 'Tom' }
    }]
).on('change', result => {
    console.log(result);
});
collection.watch(
    [{
        $match: {
            $and: [ { 'fullDocument.name': 'Tom' }, { $or: [ { 'operationType': 'insert' }, { 'operationType': 'delete' } ] } ]
        }
    }]
).on('change', result => {
    console.log(result);
});
这只返回insert

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

fullDocument
在delete事件中被省略,因此
'fullDocument.name':'Tom'
永远不会为真