<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:53 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-805] MongoDB 2.4.5 Win7 64bit fails to insert via standard csharp-driver 1.8.2</title>
                <link>https://jira.mongodb.org/browse/CSHARP-805</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Hi&lt;/p&gt;

&lt;p&gt;Sorry if this is a rookie mistake but I could net get inserts or updates to work. However, inserts using mongo.exe command line works just fine.&lt;/p&gt;

&lt;p&gt;Here is my code, no errors returned, just DocumentsAffected == 0&lt;/p&gt;

&lt;p&gt;Please Help!!!&lt;/p&gt;

&lt;p&gt;using System;&lt;br/&gt;
using System.Collections.Generic;&lt;br/&gt;
using System.Linq;&lt;br/&gt;
using System.Text;&lt;br/&gt;
using System.Threading.Tasks;&lt;br/&gt;
using MongoDB.Driver;&lt;br/&gt;
using MongoDB.Bson;&lt;/p&gt;

&lt;p&gt;namespace MyProjectNamespace.MongoConsoleApp&lt;br/&gt;
{&lt;br/&gt;
    public class Entity&lt;br/&gt;
    {&lt;br/&gt;
        public ObjectId Id &lt;/p&gt;
{ get; set; }&lt;br/&gt;
        public string Name { get; set; }
&lt;p&gt;    }&lt;/p&gt;

&lt;p&gt;    class Program&lt;br/&gt;
    {&lt;br/&gt;
        static void Main(string[] args)&lt;br/&gt;
        {&lt;br/&gt;
            string connectionString = &quot;mongodb://localhost/test?w=1&quot;;&lt;br/&gt;
            var client = new MongoClient(connectionString);&lt;br/&gt;
            var entity = new Entity();&lt;br/&gt;
            entity.Name = &quot;test&quot;;&lt;/p&gt;

&lt;p&gt;            var server = client.GetServer();&lt;br/&gt;
            var database = server.GetDatabase(&quot;test&quot;);&lt;/p&gt;

&lt;p&gt;            using (database.RequestStart())&lt;br/&gt;
            {&lt;br/&gt;
                var collection = database.GetCollection(&quot;entities&quot;);&lt;br/&gt;
                collection.Insert(entity);&lt;br/&gt;
                var result = database.GetLastError(); // use database instead of server&lt;br/&gt;
                Console.WriteLine(&quot;mongodb: docs affected: &lt;/p&gt;
{0}&quot;, result.DocumentsAffected);&lt;br/&gt;
                if (result.ErrorMessage != null)&lt;br/&gt;
                {&lt;br/&gt;
                    Console.WriteLine(&quot;mongodb: {0}
&lt;p&gt;&quot;, result.ErrorMessage);&lt;br/&gt;
                }&lt;br/&gt;
                if (result.HasLastErrorMessage)&lt;br/&gt;
                {&lt;br/&gt;
                    Console.WriteLine(&quot;mongodb: &lt;/p&gt;
{0}
&lt;p&gt;&quot;, result.LastErrorMessage);&lt;br/&gt;
                }&lt;br/&gt;
            }&lt;/p&gt;

&lt;p&gt;            Console.ReadLine();&lt;br/&gt;
            //server.Disconnect(); disconnect did not help&lt;br/&gt;
        }&lt;br/&gt;
    }&lt;br/&gt;
}&lt;/p&gt;</description>
                <environment>Windows 7 64 bit MongoDB 2.4.5&lt;br/&gt;
VS 2012 .NET 4.5 &lt;br/&gt;
C# Driver 1.8.2</environment>
        <key id="86842">CSHARP-805</key>
            <summary>MongoDB 2.4.5 Win7 64bit fails to insert via standard csharp-driver 1.8.2</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="sridhar">Sridhar Nanjundeswaran</assignee>
                                    <reporter username="rob.finneran">Rob Finneran</reporter>
                        <labels>
                    </labels>
                <created>Wed, 21 Aug 2013 16:00:36 +0000</created>
                <updated>Thu, 22 Aug 2013 03:12:19 +0000</updated>
                            <resolved>Wed, 21 Aug 2013 19:04:05 +0000</resolved>
                                    <version>1.8.2</version>
                                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="408777" author="rob.finneran" created="Thu, 22 Aug 2013 03:12:19 +0000"  >&lt;p&gt;Thanks Sridhar and Craig for helping me to understand this better.&lt;/p&gt;

&lt;p&gt;I really appreciate your help.&lt;/p&gt;
</comment>
                            <comment id="408660" author="craiggwilson" created="Wed, 21 Aug 2013 23:24:47 +0000"  >&lt;p&gt;Sridhar is correct that we will thrown an Exception if you have a WriteConcern other than Unacknowledged.  The type of exception thrown will be a WriteConcernException.  Currently, there are no timeouts for writes.  However, if you have set a socket timeout and it expires, you will received a System.IO.SocketException.&lt;/p&gt;

&lt;p&gt;Regarding the blocking, it most definitely is blocking given your code above.  Not sure why you think it isn&apos;t other than it just goes really fast.  You will get a WriteConcernResult back.  If you didn&apos;t get an exception, then everything happened successfully and there really isn&apos;t a need to check that for inserts.  However, as Sridhar said, this same result is used for Updates in which the number of documents affected will have a value.&lt;/p&gt;

&lt;p&gt;Also, just to point this out, your connection string has w=1 and journal=true. When you explicitly pass in WriteConcern.Acknowledged, you are overriding the connection string settings.&lt;/p&gt;</comment>
                            <comment id="408658" author="sridhar" created="Wed, 21 Aug 2013 23:15:49 +0000"  >&lt;p&gt;GetLastErrorResults.DocumentAffected (n in the result of the getLastError command) is only set for updates. So if you issue an update you can then use DocumentsAffected&lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/thumbs_down.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt; to check the number of documents that got updated. For inserts GetLastErrorResults.DocumentAffected is always 0.&lt;br/&gt;
When you use WriteConcern.Acknowledged you will get an exception thrown if the insert fails (usually due to a duplicate key error).&lt;/p&gt;</comment>
                            <comment id="408624" author="rob.finneran" created="Wed, 21 Aug 2013 22:26:55 +0000"  >&lt;p&gt;Hi Craig, &lt;/p&gt;

&lt;p&gt;Thanks for all your hard work!&lt;/p&gt;

&lt;p&gt;I was mistaken in that the record was not written. It was, so this is good news. &lt;/p&gt;

&lt;p&gt;However, I still think there is a bug! &lt;/p&gt;

&lt;p&gt;The WriteConcern.Acknowledged feature would not be of much use if the client program was not informed of the acknowledgement. DocumentsAffected and getLastError should tell us if the updated succeeded or not. My client code should be able to retry or determine another course of action (like to quit the program)&lt;br/&gt;
if writes were not 100% successful.&lt;/p&gt;

&lt;p&gt;I changed my connection string to:&lt;/p&gt;

&lt;p&gt;            string connectionString = &quot;mongodb://localhost/test?w=1&amp;amp;journal=true&quot;;&lt;/p&gt;

&lt;p&gt;and my insert statement to:&lt;/p&gt;

&lt;p&gt;                collection.Insert(entity, WriteConcern.Acknowledged);&lt;/p&gt;

&lt;p&gt;You would think that the C# driver should block (according to my reading of the mongodb docs, it should) and it would block until the write was successful or timed out (or some other error). I&apos;m not sure how easy it is to test this behavior, but let us assume for the moment it does. &lt;/p&gt;

&lt;p&gt;If it did block, the sending thread should get some result back, or at least could query for the result. &lt;br/&gt;
The docs imply at least at minimum the driver should throw an exception, or set the last error if the call was not successful. What error should I trap for timeouts?&lt;/p&gt;

&lt;p&gt;Is it possible that the code is ignoring the WriteConcern.Acknowledged feature or the w=1;journel=true?&lt;br/&gt;
It does not appear to behave differently than the non-safe lossy mode, unless maybe it throws an error when the write was not acknowledged, maybe?&lt;/p&gt;

&lt;p&gt;I guess I should start looking into the source code to see what is actually happening. Do you think this is a bug, a new feature request, or just a differing opinion on the right design?&lt;/p&gt;

&lt;p&gt;Thanks!!!&lt;/p&gt;

</comment>
                            <comment id="408451" author="craiggwilson" created="Wed, 21 Aug 2013 19:04:00 +0000"  >&lt;p&gt;Did you actually check the database to see if your documents were there?  I ran your program above and I also get documentsAffected = 0, but the documents exist in the database.  I can&apos;t find any documentation for whether or not this should be 1 or 0.  However, when I run this in the shell and explicitly run getLastError after I perform an insert, 0 is returned for &apos;n&apos;, which is the number of documents affected.  &lt;/p&gt;

&lt;p&gt;If you&apos;d like to file a server bug, feel free, but this is not a bug in the .NET driver as we just report what the server tells us.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </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|hrseo7:</customfieldvalue>

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