Watch with pipeline insert / update

MongoDB Atlas v3.6, Node Driver v3.6.2

I have a db to which items are added / updated.

I’m using collection.watch(pipeline)

The pipeline has $match on client_id ( string of o_id )

The ‘insert’ watch

[
 {
  "$match": {
   "operationType": "insert",
   "fullDocument.client_id": "5f6f69b96783940464d0ae1c"
  }
 }
]

and this works fine - ie, only inserts with the matching client_id are included in the stream.

However I also have

[
 {
  "$match": {
   "operationType": "update",
   "fullDocument.client_id": "5f6f69b96783940464d0ae1c"
  }
 }
]

Which never matches any document updates ??

Any ideas ?

Hi @Peter_Alderson,

I believe this is as you have to specify updateLookup=true to get q fullDocument field in the event with update.

This is not a default behaviour therefore cause you to miss match the events:

Change Streams — MongoDB Manual

Best
Pavel

Hi @Pavel_Duchovny,

I’ve now tried…

[
 {
  "$match": {
   "operationType": "update",
   "fullDocument": "updateLookup"
  }
 }
]

This is as suggested in the link for nodejs, but still there are no updates received on this watch !

Best
Peter

Hi @Peter_Alderson,

This is wrongly done. The "fullDocument": "updateLookup" is not part of the $match stage.

Its an option document provided as part of Watch
: collection.watch(pipeline,options)

.watch([
 {
  "$match": {
   "operationType": "update",
   "fullDocument.client_id": "5f6f69b96783940464d0ae1c"
  }
 }
],
{ "fullDocument": "updateLookup"})

Best
Pavel

Thanks! That solved the issue.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.