Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6699417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:41:34+00:00 2026-05-26T06:41:34+00:00

In our application we are doing large amounts of inserts/updates (anywhere from 1k to

  • 0

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.

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.

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.

(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)

        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 =>
            {
                var query = new QueryDocument("_id", i);
                coll.Update(query, Update.Set("value",100), 
                             UpdateFlags.Upsert, SafeMode.False);;
            });
        }

So I guess my question is: What is the best way to do large numbers of updates fast, with 100% success rate?

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:41:34+00:00Added an answer on May 26, 2026 at 6:41 am

    When you use SafeMode.False the C# driver just writes the Insert/Update messages to the socket and doesn’t wait for a reply. When you write a lot of data very quickly to a socket it’s going to get buffered on the client side, and the networking stack will squirt the bytes out on the network as fast as it can. If you are saturating the network, things can get backed up quite a bit.

    My guess is that you are exiting your process before the networking stack has had a chance to write all remaining bytes out to the network. That would explain the lost documents.

    Your best best is to call Count at the end, not once, but repeatedly, until the count equals what you think it should be. At that point you know there is no data left to be transmitted.

    However, if any of the inserts failed for any reason (for example, violating a unique index), the count will never reach your expected value. There is no 100% way of knowing whether an Insert/Update worked without using SafeMode.True.

    Note that most long lived server processes never have this problem because they never exit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While doing loadtesting on our application I noticed that if you use @Transactional and
We have some part of our application that need to load a large set
Our application is modulraized (Group of modules doing specific things). The modules have event
We need to represent huge numbers in our application. We're doing this using integer
Our application is a Java-GWT application that uses Guice-Persist and Guice-Servlet extensively. We have
Our application stores records with shorter texts (strings of 100-1000 characters). It provides search
Our application takes text from a web form and sends it via email to
Our application downloads data from the internet using RSS but is having connection problems
I am currently in process of making our application Large Address Aware. As experience
We have a .NET application which our customers consider too large for mass deployment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.