Why Matchedcount is different than Modified Count in acknowledgement of Bulkwrite

I have tried collection.bulk_write(bulkset) for insert, update as well as delete operations. But, matchcount and modifiedcount / insertcount / deletecount do not match.

May I know possible reasons for this mismatch

A document might match the query but does not need to be updated.

{ _id : 0 , foo : 1 , bar : 1 }
{ _id : 1 , foo : 1 , bar : 2 }

c.updateMany( { foo : 1 } , { "$set" : { bar : 2 } } )

The above will have a match count of 2 because both documents have foo:1 but update count will be 1 because document _id:1 already has bar:2 so only document _id:0 will be updated.

1 Like

Yes. I realized it later on