<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:06 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-530] Dublicate Key error while upset</title>
                <link>https://jira.mongodb.org/browse/CSHARP-530</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;When I want to upsert my record I get duplicate key error.&lt;br/&gt;
The Code:&lt;br/&gt;
var update_query = Query.And(&lt;br/&gt;
                       Query.EQ(&quot;Id&quot;, item.Id)        ,               ,&lt;br/&gt;
                       Query.EQ(&quot;UserId&quot;, item.UserId),&lt;br/&gt;
                       Query.EQ(&quot;Email&quot;,item.Email)&lt;br/&gt;
                       );&lt;br/&gt;
                   var resxs= coll.Update(update_query,&lt;br/&gt;
                       Update.Replace(item),&lt;br/&gt;
                       UpdateFlags.Upsert&lt;br/&gt;
                       );&lt;/p&gt;

&lt;p&gt;But when I remove &quot;Id&quot; criteria,the code works and doing upset.&lt;br/&gt;
Is there anything I am missing.&lt;/p&gt;

&lt;p&gt;thnx&lt;/p&gt;</description>
                <environment>MongoDB runs on ubuntu server lts 12, development environment  is Windows 2008 R2 Ent Server with VS 2010</environment>
        <key id="44613">CSHARP-530</key>
            <summary>Dublicate Key error while upset</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="5">Cannot Reproduce</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="e2burner">erhan</reporter>
                        <labels>
                            <label>crash</label>
                            <label>driver</label>
                            <label>dublicate</label>
                            <label>error</label>
                            <label>key</label>
                            <label>question</label>
                            <label>upsert</label>
                    </labels>
                <created>Tue, 17 Jul 2012 22:19:17 +0000</created>
                <updated>Fri, 5 Apr 2019 13:59:02 +0000</updated>
                            <resolved>Wed, 22 Aug 2012 14:32:18 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="155754" author="rstam" created="Wed, 22 Aug 2012 14:31:41 +0000"  >&lt;p&gt;Closing this ticket as unable to reproduce (and no further information provided).&lt;/p&gt;</comment>
                            <comment id="144849" author="rstam" created="Thu, 19 Jul 2012 14:14:07 +0000"  >&lt;p&gt;One thing that seems odd is that the JSON document returned by item.ToJson() does not have an &quot;_id&quot; element (but it does have an &quot;Id&quot; element). Normally a C# property called &quot;Id&quot; is automatically mapped to &quot;_id&quot; in the database. Can you show your class definition for item?&lt;/p&gt;

&lt;p&gt;There is also something odd about BirthDate. In the database they are stored as BSON DateTime values (see ISODate), but in the document returned by item.ToJson() they appear to be strings formatted in an unusual way (&quot;/Date(612824400000+0300)/&quot;).&lt;/p&gt;</comment>
                            <comment id="144790" author="e2burner" created="Thu, 19 Jul 2012 08:14:20 +0000"  >&lt;p&gt;Before modify the record :&lt;br/&gt;
&amp;gt; db.user.find({_id:1})&lt;/p&gt;
{ &quot;_id&quot; : NumberLong(1), &quot;UserId&quot; : &quot;20277B19-F603-4CA1-8B3A-B2A009BB291A-@o@-1E43F402-0A2E-4E11-9708-15F7AD9EFA82&quot;, &quot;Email&quot; : &quot;xxxxxx@hotmail.com&quot;, &quot;FirstName&quot; : &quot;xxxx&quot;, &quot;LastName&quot; : &quot;yyyyy&quot;, &quot;BirthDate&quot; : ISODate(&quot;1989-06-02T21:00:00Z&quot;), &quot;Password&quot; : &quot;test&quot;, &quot;Gender&quot; : 0, &quot;CityId&quot; : 7, &quot;TownId&quot; : 0, &quot;IsDisabled&quot; : 1, &quot;IsGlobalDisabled&quot; : 0, &quot;IsRegKeySent&quot; : -1, &quot;IsRegKeyValid&quot; : -1, &quot;LastSeenOn&quot; : null, &quot;ParentUserId&quot; : null, &quot;RegisteredOn&quot; : null, &quot;ValidatedOn&quot; : null, &quot;ParishId&quot; : 0, &quot;CityName&quot; : &quot;-&quot;, &quot;TownName&quot; : null, &quot;ParishName&quot; : null, &quot;IsSentToSql&quot; : 0 }


&lt;p&gt;CityName value changed in c# :&lt;br/&gt;
item.ToJson()&lt;br/&gt;
&quot;&lt;/p&gt;
{\&quot;CityName\&quot;:\&quot;Antalya\&quot;,\&quot;IsSentToSql\&quot;:0,\&quot;UserId\&quot;:\&quot;20277B19-F603-4CA1-8B3A-B2A009BB291A-@o@-1E43F402-0A2E-4E11-9708-15F7AD9EFA82\&quot;,\&quot;Email\&quot;:\&quot;xxxxxx@hotmail.com\&quot;,\&quot;FirstName\&quot;:\&quot;xxxx\&quot;,\&quot;LastName\&quot;:\&quot;yyyyy\&quot;,\&quot;BirthDate\&quot;:\&quot;\\/Date(612824400000+0300)\\/\&quot;,\&quot;Password\&quot;:\&quot;test\&quot;,\&quot;Gender\&quot;:0,\&quot;CityId\&quot;:7,\&quot;TownId\&quot;:0,\&quot;IsDisabled\&quot;:1,\&quot;IsGlobalDisabled\&quot;:0,\&quot;IsRegKeySent\&quot;:-1,\&quot;IsRegKeyValid\&quot;:-1,\&quot;Id\&quot;:1,\&quot;ParishId\&quot;:0}
&lt;p&gt;&quot;&lt;/p&gt;


&lt;p&gt;After update the record ( without Id criteria in query):&lt;br/&gt;
&amp;gt; db.user.find({_id:1})&lt;/p&gt;
{ &quot;_id&quot; : NumberLong(1), &quot;UserId&quot; : &quot;20277B19-F603-4CA1-8B3A-B2A009BB291A-@o@-1E43F402-0A2E-4E11-9708-15F7AD9EFA82&quot;, &quot;Email&quot; : &quot;xxxxxx@hotmail.com&quot;, &quot;FirstName&quot; : &quot;xxxx&quot;, &quot;LastName&quot; : &quot;yyyyy&quot;, &quot;BirthDate&quot; : ISODate(&quot;1989-06-02T21:00:00Z&quot;), &quot;Password&quot; : &quot;test&quot;, &quot;Gender&quot; : 0, &quot;CityId&quot; : 7, &quot;TownId&quot; : 0, &quot;IsDisabled&quot; : 1, &quot;IsGlobalDisabled&quot; : 0, &quot;IsRegKeySent&quot; : -1, &quot;IsRegKeyValid&quot; : -1, &quot;LastSeenOn&quot; : null, &quot;ParentUserId&quot; : null, &quot;RegisteredOn&quot; : null, &quot;ValidatedOn&quot; : null, &quot;ParishId&quot; : 0, &quot;CityName&quot; : &quot;Antalya&quot;, &quot;TownName&quot; : null, &quot;ParishName&quot; : null, &quot;IsSentToSql&quot; : 0 }</comment>
                            <comment id="144732" author="rstam" created="Thu, 19 Jul 2012 00:01:16 +0000"  >&lt;p&gt;From the error message it looks like the duplicate key is on the _id field with a value of 1. You can display this document in the mongo shell using:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&amp;gt; db.coll.findOne({_id:1})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;Replace &quot;coll&quot; with the actual name of your collection.&lt;/p&gt;

&lt;p&gt;If you could provide the document as displayed by the mongo shell, as well as setting a breakpoint in Visual Studio on your call to Update and type item.ToJson() in the Visual Studio immediate window and report that back as well.&lt;/p&gt;</comment>
                            <comment id="144295" author="e2burner" created="Wed, 18 Jul 2012 06:22:32 +0000"  >&lt;p&gt;Hello , I could not gather any error msg by using mongo shell but I&apos;ve copied the exception msg generated by C# below.&lt;br/&gt;
And I modify 3 different fields before update.These fields are not index fields.&lt;/p&gt;

&lt;p&gt;MongoDB.Driver.MongoSafeModeException was unhandled&lt;br/&gt;
  Message=Safemode detected an error &apos;E11000 duplicate key error index: test.user.$&lt;em&gt;id&lt;/em&gt;  dup key: { : 1 }&apos;. (Response was { &quot;err&quot; : &quot;E11000 duplicate key error index: test.user.$&lt;em&gt;id&lt;/em&gt;  dup key: { : 1 }&quot;, &quot;code&quot; : 11000, &quot;n&quot; : 0, &quot;connectionId&quot; : 183, &quot;ok&quot; : 1.0 }).&lt;br/&gt;
  Source=MongoDB.Driver&lt;br/&gt;
  StackTrace:&lt;br/&gt;
       at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message, SafeMode safeMode) in C:\source\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 516&lt;br/&gt;
       at MongoDB.Driver.MongoCollection.Update(IMongoQuery query, IMongoUpdate update, MongoUpdateOptions options) in C:\source\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 1512&lt;br/&gt;
       at MongoDB.Driver.MongoCollection.Update(IMongoQuery query, IMongoUpdate update, UpdateFlags flags) in C:\source\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 1544&lt;br/&gt;
       at Sso.DataEngine.UserEngine.Start() in D:\Repository\clients\test\Sso\Sso.DataEngine\UserEngine.cs:line 70&lt;br/&gt;
       at Sso.DataEngine.EngineBase.ToMongoDB(String[] args) in D:\Repository\clients\test\Sso\Sso.DataEngine\EngineBase.cs:line 48&lt;br/&gt;
       at Sso.DataEngine.Program.Main(String[] args) in D:\Repository\clients\test\Sso\Sso.DataEngine\Program.cs:line 38&lt;br/&gt;
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)&lt;br/&gt;
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)&lt;br/&gt;
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()&lt;br/&gt;
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)&lt;br/&gt;
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)&lt;br/&gt;
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)&lt;br/&gt;
       at System.Threading.ThreadHelper.ThreadStart()&lt;br/&gt;
  InnerException: &lt;/p&gt;</comment>
                            <comment id="144237" author="rstam" created="Tue, 17 Jul 2012 22:27:03 +0000"  >&lt;p&gt;It would help if you could provide the document (using the mongo shell) that your are getting the exception with as well as the full error message. Does the full error message tell you which index is the cause of the duplicate key?&lt;/p&gt;

&lt;p&gt;Are you modifying any values of your item variable before calling Update?&lt;/p&gt;</comment>
                            <comment id="144236" author="e2burner" created="Tue, 17 Jul 2012 22:22:42 +0000"  >&lt;p&gt;PS:I have unique indexes on Email and UserId. &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|hrh79z:</customfieldvalue>

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