We are using the csharp
MongoDB.Driver library, version 2.13.1.
During our integration tests, the
UpdateManyAsync method occasionally acts weirdly.
The flow is the following:
- We call
await UpdateManyAsyncwith a
Let’s say that we try to update a specific field for several entities which is currently X, and we want to update it to Y.
- We print the
UpdateResultof the operation and see the following fields in the result:
- We query the DB, retrieve the entities that should have been updated and verify that they were indeed updated. All entities have the field set to Y.
- After several seconds, a different flow queries the DB and retrieves all entities.
In some cases (again, it happens from time to time), the field value is X and our tests fail.
- There is no flow which updates these entities between steps 3 and 4.
- This happens in our integration tests flow, in which the MongoDB is built via docker-compose.
No read-write replica or something of the sort.
- There are several tests that suffer from this inconsistency, all of them use UpdateManyAsync.
- We have yet to find it happen in our production environment, but it doesn’t mean it that it didn’t happen.
- This happens once in a while, most of the times all works properly.
- We have yet to see this with any other MongoDB driver API. Only in
The only guess we currently have (rather than some read-write replica implementation which we don’t really think exists when using a simple docker-compose setup), is some caching done by the csharp driver.
Is it possible that it sets some internal state (and therefore the changes are reflected properly when queried in the same flow) and fails to persist it to the actual DB from time to time?
Any help will really be appreciated here.