Hello. I have a collection called ‘locations’ and it has 64 documents, each has a field called ‘subscribers’ and the value is an array of email addresses. When I tried to run db.collection('locations') .updateMany({},{ $pull: {subscribers: 'some@email.com'} });
and db.collection('locations') .updateMany({},{ $addToSet: {subscribers: 'some@email.com'} });
again and again, the modifiedCount
should always be 64, right? But it returns a random number every time and loses data. The matchedCount
is always 64, no error. Why does that happen? It’s weird because when I try these updates on a test db and collection, it doesn’t happen, but on my production db and collection, it happens. Is it because I have too frequent queries that locks the documents? But mongodb has journal that can help recover from heavy load, doesn’t it? I am so confused. Please help!
I am running on an M2 cluster and there are a couple of connections querying and updating the cluster. I use the Node.js driver.