MongoDB $match


MongoDB Atlas Cluster v3.6

I have a watch stram and want to apply a filter.

My Watch starts with…

const stream = collection('mydb').watch([
   { $match: { 
       operationType: { 
          $in: ['insert','update'] }, 
          'fullDocument.client_id': client_id+'' 

Where client_id is object in the document ( sting of o_id );

I’ve also tried…

const stream = collection('mydb').watch([
   { $match: { 
        client_id: client_id+'' 

But in both cases the stream includes updates for all changes to ‘mydb’ irrespective of a match on client_id ?

Any ideas where I’m going wrong ?

Hi @Peter_Alderson

The pipeline seems to be malformed. Why is there a double quote in the end of client_id field value?

Where do you run this code, in node or mongo shell?

Have you tried using a parameter and printing the match stage so you see its correct?

Is the collection name mydb?


I think there may have been a typo in the copy, so here are the stringified versions of the actual pipelines

I’ve just re-tried the first pipeline, see below, and this now seems to be working OK.

Not sure what I got wrong, but thanks for your guidance.


  "$match": {
   "operationType": {
    "$in": [
   "fullDocument.client_id": "5f69cbbb01e0610ab651e146"
1 Like