Question

I'm doing two consecutive writes into the MongoDB (no shards, no replicas):

  1. insert data into db
  2. find and modify data inserted in 1.

when performing step 2), is it granted, that the command sees the data insertion from step 1)? What is the minimal WriteConcern I should use in step 1) to ensure this?

As for my use-case, I know, I could merge 1 and 2 into one simple step; however, my real use-case is much more complicated and cannot be solved such easily.

Was it helpful?

Solution

Your use case will work given you are using a write concern of Acknowledged. This is the default write concern in MongoDB 2.2 or later given you are using a recent driver (see here for the minimum driver version required).

http://docs.mongodb.org/manual/release-notes/drivers-write-concern/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top