Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-329

A very simple mongodb insert code gave wrong result

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 1.2
    • Fix Version/s: None
    • Component/s: None
    • Environment:
    • # Replies:
      3
    • Last comment by Customer:
      false

      Description

      As I'm studying MongoDB I create a smplest mongodb code as the following:

      //-----------Begining-----------

      var mongo = MongoServer.Create("mongodb://192.168.56.101:27017"); //My mongodb server runing on my virtual box

      for (int i = 0; i < 100000; i++)
      {
      var tmp = new BsonDocument {

      { "a", i }

      };

      mongo["db"]["foo"].Insert(tmp);
      }

      ///--------------End------------//

      Simple enough, right? Things got weired when I try to get the count of db.foo, here's the output from my linux console:

      1. ./mongo
        MongoDB shell version: 2.0.0
        connecting to: test
        > db.foo.count() <--- Before I ran the sample code above
        0
        > use db
        switched to db db
        > db.foo.count()
        98954 <--- After
        >

      //-------

      According to the sample code, where it is 98954 should be 100000.

      I've repeated this code many times, results vary but none of them reached 100000.

      To be more sure, I run the same code using WinForm instead of WinConsole project, magically every single time the result is right. The same with Website Project. So I can be certain there's nothing wrong with my mongodb server but very likely something wrong with the driver with winconsole mode under my VS C# 2010.

      I also gave this code to some of my coleagues who confirmed my above findings.

        Attachments

          Activity

            People

            • Assignee:
              rstam Robert Stam
              Reporter:
              wizbe WizBe Li
              Participants:
              Last commenter:
              Rathi Gnanasekaran
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                7 years, 17 weeks, 4 days ago
                Date of 1st Reply: