I’m using Mongoose and MongoDB and Nodejs and I want to listen for changes if updatedFields has more then one key.
Can i check updateDescription.updatedFields keys size ?
I can check every key like this:
const filter = [{
$match: {
$or: [
{ "updateDescription.updatedFields.key0": { $exists: true } },
{ "updateDescription.updatedFields.key1": { $exists: true } },
{ "updateDescription.updatedFields.key2": { $exists: true } },
{ "updateDescription.updatedFields.key3": { $exists: true } }
// ...
]
}
}];
const options = { fullDocument: 'updateLookup', fullDocumentBeforeChange: 'whenAvailable' };
myModel.collection('myCollection').watch(filter, options).on('change', async (event) =>
{
console.log('event:', event);
});