<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:30 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-329] A very simple mongodb insert code gave wrong result</title>
                <link>https://jira.mongodb.org/browse/CSHARP-329</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;As I&apos;m studying MongoDB I create a smplest mongodb code as the following:&lt;/p&gt;

&lt;p&gt;//-----------&lt;del&gt;Begining&lt;/del&gt;-----------&lt;/p&gt;

&lt;p&gt;  var mongo = MongoServer.Create(&quot;mongodb://192.168.56.101:27017&quot;); //My mongodb server runing on my virtual box&lt;/p&gt;

&lt;p&gt;  for (int i = 0; i &amp;lt; 100000; i++)&lt;br/&gt;
  {&lt;br/&gt;
                var tmp = new BsonDocument { &lt;/p&gt;
{ &quot;a&quot;, i }
&lt;p&gt; };&lt;/p&gt;

&lt;p&gt;                mongo&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;db&amp;quot;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;foo&amp;quot;&amp;#93;&lt;/span&gt;.Insert(tmp);&lt;br/&gt;
  }&lt;/p&gt;

&lt;p&gt;///--------------&lt;del&gt;End&lt;/del&gt;------------//&lt;/p&gt;

&lt;p&gt;Simple enough, right? Things got weired when I try to get the count of db.foo, here&apos;s the output from my linux console:&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;./mongo&lt;br/&gt;
MongoDB shell version: 2.0.0&lt;br/&gt;
connecting to: test&lt;br/&gt;
&amp;gt; db.foo.count()   &amp;lt;--- Before I ran the sample code above&lt;br/&gt;
0&lt;br/&gt;
&amp;gt; use db&lt;br/&gt;
switched to db db&lt;br/&gt;
&amp;gt; db.foo.count()&lt;br/&gt;
98954              &amp;lt;--- After&lt;br/&gt;
&amp;gt;&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;//-------&lt;/p&gt;

&lt;p&gt;According to the sample code, where it is 98954 should be 100000. &lt;/p&gt;

&lt;p&gt;I&apos;ve repeated this code many times, results vary but none of them reached 100000.&lt;/p&gt;

&lt;p&gt;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&apos;s nothing wrong with my mongodb server but very likely something wrong with the driver with winconsole mode under my VS C# 2010. &lt;/p&gt;

&lt;p&gt;I also gave this code to some of my coleagues who confirmed my above findings.&lt;/p&gt;

</description>
                <environment>Windows 2008 R2 64bit, MS Visual C# 2010. Sample code using Windows Console project&lt;br/&gt;
&lt;br/&gt;
Driver is the latest official driver (1.2.0.4274)&lt;br/&gt;
&lt;br/&gt;
MongoDB:&lt;br/&gt;
&lt;br/&gt;
Mon Sep 19 19:25:52 [initandlisten] db version v2.0.0, pdfile version 4.5&lt;br/&gt;
Mon Sep 19 19:25:52 [initandlisten] git version: nogitversion&lt;br/&gt;
Mon Sep 19 19:25:52 [initandlisten] build info: Linux liyong-vm.letao.com 2.6.32-71.29.1.el6.x86_64 #1 SMP Mon Jun 27 19:49:27 BST 2011 x86_64 BOOST_LIB_VERSION=1_41&lt;br/&gt;
</environment>
        <key id="22744">CSHARP-329</key>
            <summary>A very simple mongodb insert code gave wrong result</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="wizbe">WizBe Li</reporter>
                        <labels>
                            <label>C#</label>
                            <label>ConsoleApplication</label>
                            <label>Count</label>
                            <label>Insert</label>
                    </labels>
                <created>Fri, 23 Sep 2011 16:21:18 +0000</created>
                <updated>Wed, 19 Oct 2016 14:16:09 +0000</updated>
                            <resolved>Fri, 23 Sep 2011 19:25:48 +0000</resolved>
                                    <version>1.2</version>
                                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="56242" author="rstam" created="Fri, 23 Sep 2011 19:25:48 +0000"  >&lt;p&gt;No problem. Glad it was something simple!&lt;/p&gt;</comment>
                            <comment id="56216" author="wizbe" created="Fri, 23 Sep 2011 17:38:57 +0000"  >&lt;p&gt;Thanks for the quick response.&lt;/p&gt;

&lt;p&gt;I added a line to have the thread sleep for 3 seconds and problem goes away. &lt;/p&gt;

&lt;p&gt;Sorry for the troubling, thought it would be some concepts I missed about the driver.&lt;/p&gt;

&lt;p&gt;Wish a wonderful future for mongodb and all you developers.&lt;/p&gt;
</comment>
                            <comment id="56199" author="rstam" created="Fri, 23 Sep 2011 16:52:51 +0000"  >&lt;p&gt;When you do inserts with SafeMode off the messages are queued in the outgoing TCP/IP buffers and Insert returns immediately even before the message has been sent on the network. If you let the process exit before the TCP/IP buffers have had a chance to drain out some of the messages will never have been sent, resulting in the lower count that you are seeing.&lt;/p&gt;

&lt;p&gt;There are two alternatives:&lt;/p&gt;

&lt;p&gt;1. Use SafeMode.True, so the process waits for each Insert to complete before continuing&lt;br/&gt;
2. Don&apos;t let the process exit until the TCP/IP buffers have all been sent&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="13264" name="mongo.png" size="12362" author="wizbe" created="Fri, 23 Sep 2011 16:21:18 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrh8d3:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14154</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>