[CSHARP-530] Dublicate Key error while upset Created: 17/Jul/12 Updated: 05/Apr/19 Resolved: 22/Aug/12 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | erhan | Assignee: | Robert Stam |
| Resolution: | Cannot Reproduce | Votes: | 0 |
| Labels: | crash, driver, dublicate, error, key, question, upsert | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
MongoDB runs on ubuntu server lts 12, development environment is Windows 2008 R2 Ent Server with VS 2010 |
||
| Description |
|
When I want to upsert my record I get duplicate key error. But when I remove "Id" criteria,the code works and doing upset. thnx |
| Comments |
| Comment by Robert Stam [ 22/Aug/12 ] | |
|
Closing this ticket as unable to reproduce (and no further information provided). | |
| Comment by Robert Stam [ 19/Jul/12 ] | |
|
One thing that seems odd is that the JSON document returned by item.ToJson() does not have an "_id" element (but it does have an "Id" element). Normally a C# property called "Id" is automatically mapped to "_id" in the database. Can you show your class definition for item? 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 ("/Date(612824400000+0300)/"). | |
| Comment by erhan [ 19/Jul/12 ] | |
|
Before modify the record : CityName value changed in c# : " After update the record ( without Id criteria in query): | |
| Comment by Robert Stam [ 19/Jul/12 ] | |
|
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:
Replace "coll" with the actual name of your collection. 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. | |
| Comment by erhan [ 18/Jul/12 ] | |
|
Hello , I could not gather any error msg by using mongo shell but I've copied the exception msg generated by C# below. MongoDB.Driver.MongoSafeModeException was unhandled | |
| Comment by Robert Stam [ 17/Jul/12 ] | |
|
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? Are you modifying any values of your item variable before calling Update? | |
| Comment by erhan [ 17/Jul/12 ] | |
|
PS:I have unique indexes on Email and UserId. |