Reputation: 79
Using Mongo 2.4.9 with C# driver 1.8.3
With the following example:
WriteConcern concern = WriteConcern.Unacknowledged;
for(int i=0;i<100;i++){
if(i==99)concern=WriteConcern.Acknowledged;
collection.Update(Query.EQ("i",i),Update.Set("i2",i),concern);
}
// Can I assume that all writes in this loop have now been 'committed'?
My aim is that I perform the first 99 updates as quickly as possible, without acknowledgement, and then on the last once, ask for acknowledgement, so I know that all 100 updates occurred
Does the code above make sense, or work? If not, is there a better way to achieve this?
Failing that, should I wait for the release of MongoDB 2.6 and the bulk apis?
Thanks, Ben
Upvotes: 1
Views: 754
Reputation: 65323
My aim is that I perform the first 99 updates as quickly as possible, without acknowledgement, and then on the last once, ask for acknowledgement, so I know that all 100 updates occurred
There's a logic flaw here: you will only know the success of the last Acknowledged
update, and can't make much inference on the first 99 Unacknowledged
updates aside from them not throwing obvious network exceptions.
Does the code above make sense, or work? If not, is there a better way to achieve this?
In MongoDB 2.4 and earlier, if you want Acknowledged
updates you will have to send them individually.
Failing that, should I wait for the release of MongoDB 2.6 and the bulk apis?
For your use case, the new bulk write APIs will definitely be more suitable. You can try out the BulkWrite API with the release candidates for the C# 1.9 driver and MongoDB 2.6.
FYI, if you want to do Bulk Inserts (rather than bulk updates) these are already supported in MongoDB 2.4 and earlier.
Upvotes: 3