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

  • Home
  • SEARCH
  • 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 6846299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:36:16+00:00 2026-05-27T00:36:16+00:00

From the C# documentation: The Save method is a combination of Insert and Update.

  • 0

From the C# documentation:

The Save method is a combination of Insert and Update. If the Id member of the document has a value, then it is assumed to be an existing document and Save calls Update on the document (setting the Upsert flag just in case it actually is a new document after all).

I’m creating my IDs manually in a base class that all my domain objects inherit from. So all my domain objects have an ID when they are inserted into MongoDB.

Questions is, should I use collection.Save and keep my interface simple or does this actually result in some overhead in the Save-call (with the Upsert flag), and should I therefor use collection.Insert and Update instead?

What I’m thinking is that the Save method is first calling Update and then figures out that my new object didn’t exist in the first place, and then call Insert instead. Am I wrong? Has anyone tested this?

Note: I insert bulk data with InsertBatch, so big datachunks won’t matter in this case.

Edit, Follow up

I wrote a small test to find out if calling Update with Upsert flag had some overhead so Insert might be better. Turned out that they run at the same speed. See my test code below. MongoDbServer and IMongoDbServer is my own generic interface to isolate the storage facility.

IMongoDbServer server = new MongoDbServer();
Stopwatch sw = new Stopwatch();
long d1 = 0;
long d2 = 0;
for (int w = 0; w <= 100; w++)
{
    sw.Restart();
    for (int i = 0; i <= 10000; i++)
    {
        ProductionArea area = new ProductionArea();
        server.Save(area);
    }
    sw.Stop();
    d1 += sw.ElapsedMilliseconds;
    sw.Restart();
    for (int i = 0; i <= 10000; i++)
    {
        ProductionArea area = new ProductionArea();
        server.Insert(area);
    }
    sw.Stop();
    d2 += sw.ElapsedMilliseconds;
}
long a1 = d1/100;
long a2 = d2/100;
  • 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-27T00:36:16+00:00Added an answer on May 27, 2026 at 12:36 am

    The Save method is not going to make two trips to the server.

    The heuristic is this: if the document being saved does not have a value for the _id field, then a value is generated for it and then Insert is called. If the document being saved has a non-zero value for the _id, then Update is called with the Upsert flag, in which case it is up to the server to decide whether to do an Insert or an Update.

    I don’t know if an Upsert is more expensive than an Insert. I suspect they are almost the same and what really matters is that either way it is a single network round trip.

    If you know it’s a new document you might as well call Insert. And calling InsertBatch is way more performant than calling many individual Inserts. So definitely prefer InsertBatch to Save.

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

Sidebar

Related Questions

In CouchDb's documentation, the described method of deleting document attachments is to send a
Here is a method used to save data to a file which has stumped
Im trying to read the return value of a Java Method and save it
From the documentation I read you can do this: db.people.update( { name:Joe }, {
From the documentation of UITableView / UITableViewController: If you decide to use a UIViewController
I've received some documentation from one of our suppliers for a webservice they're publishing
I couldn't figure out that from SASS documentation. For example I would like to
I can't seem to find any useful documentation from Microsoft about how one would
Is there an easy way to produce MSDN-style documentation from the Visual Studio XML
So I'm working on this class that's supposed to request help documentation from a

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.