Note that there are some explanatory texts on larger screens.

plurals
  1. POPerformance difference between MongoServer.Create() and mongoClient.GetServer() in MongoDb
    primarykey
    data
    text
    <p>Consider this code:</p> <pre><code> MongoServer mongo = MongoServer.Create(); mongo.Connect(); Console.WriteLine("Connected"); Console.WriteLine(); MongoDatabase db = mongo.GetDatabase("tutorial"); Stopwatch stopwatch=new Stopwatch(); stopwatch.Start(); using (mongo.RequestStart(db)) { MongoCollection&lt;BsonDocument&gt; collection = db.GetCollection&lt;BsonDocument&gt;("books"); for (int i = 0; i &lt; 100000; i++) { var nested = new BsonDocument { {"name", "John Doe"}, }; collection.Insert(nested); } } stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); Console.ReadLine(); </code></pre> <p>In the first line i use MongoServer.Create() which is obsolete.But when running above code output time is <code>3056</code>(approximately 3 seconds).</p> <p>So I use this code that is recommended by MongoDb documentation.</p> <pre><code> MongoClient mongo = new MongoClient(); var server = mongo.GetServer(); MongoDatabase db = server.GetDatabase("tutorial"); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); using (server.RequestStart(db)) { MongoCollection&lt;BsonDocument&gt; collection = db.GetCollection&lt;BsonDocument&gt;("books"); for (int i = 0; i &lt; 100000; i++) { var nested = new BsonDocument { {"name", "John Doe"}, }; collection.Insert(nested); } } stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); Console.ReadLine(); </code></pre> <p>When run above code the output time is <code>14225</code>(approximately 10 to 14 second on my PC). Why i get this performance time as a result of refactored code on new version of mongoDb.What i am missing along?</p>
    singulars
    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.
    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