My document is like this:
{
"_id": {
"$oid": "6257a55d04bf2167733f5b72"
},
"attributes": {
"CustomerName": "John",
"CustomerID": "28374",
"LoanID": "82349327409234"
},
"type": "Record"
}
My changestream watch is like this:
var watchCursor = db.transactions.watch([ {$match: {"attributes.LoanID": { $exists : true }}} ]);
while (!watchCursor.isExhausted()){
if (watchCursor.hasNext()){
print(JSON.stringify(watchCursor.next()));
}
}
But the change stream can't find this document. Any thoughts? Note that my search query is after the nested field inside attributes.
Ah the reason is because the changestream event document is not an exact copy of the actual document.
In case of an update, the actual document resides in
updateDescription.updatedFieldsand in case of an insert it resides infullDocumentfield.Ref: Mongodb change-events