Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Driver SafeMode off Upserts - not all records updated/inserted
    primarykey
    data
    text
    <p>In our application we are doing large amounts of inserts/updates (anywhere from 1k to 100k) and I noticed that not all records are being saved. It saves between 90%-95% of records with safemode off. </p> <p>Doing the upsert with safemode on upserts all records successfully but is much too slow. I remember reading somewhere that even with safemode off there should be no reason an update/insert should fail unless the server is unavailable.</p> <p>I wrote a small app to test this, and have included the code below. It tries to insert 100,000 ints into Mongo, and when checked after it is run I see about 90,000 records in the collection. </p> <p>(Note: I am using Parallel updating, since I am updating by _id and Mongo 2.0 supports parallel operations when using _id. When not using Parallel.Foreach I still see some loss of records though not as great)</p> <pre><code> MongoServer server = MongoServer.Create(host); MongoDatabase test = server.GetDatabase("testDB"); var list = Enumerable.Range(0, 100000).ToList(); using (server.RequestStart(test)) { MongoCollection coll = test.GetCollection("testCollection"); Parallel.ForEach(list, i =&gt; { var query = new QueryDocument("_id", i); coll.Update(query, Update.Set("value",100), UpdateFlags.Upsert, SafeMode.False);; }); } </code></pre> <p>So I guess my question is: What is the best way to do large numbers of updates fast, with 100% success rate?</p> <p>I can't use insert because I have a number of processes writing to Mongo and cannot be sure of whether a certain document exists or not , which is why I am using Upsert.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload