How to get actual value for duplicate index MongoDB?

74 Views Asked by At

I am interacting with MongoDB using C# driver. It threw duplicate key error like below for one index

the highlighted value 0x141214141a24 is not a actual value in the error message of location.path. how to get the actual value of it? (location.target is actual value I see)

Message : "E11000 duplicate key error collection: Database.Collection index: location.path_1_location.target_1 collation: { locale: "en_US", caseLevel: false, caseFirst: "off", strength: 1, numericOrdering: false, alternate: "non-ignorable", maxVariable: "punct", normalization: false, backwards: false, version: "57.1" } dup key: { location.path: "0x141214141a24", location.target: 457 }" } ].

1

There are 1 best solutions below

1
user20042973 On

@user20042973 no. This is not the actual value. If I query in database location.path:"0x141214141a24" , no document returned

What I was attempting to say is that 0x141214141a24 is the representation in the the specified collation of the value that is being sent to the database. I think the value being submitted by the client in your case is "101149":

> db.foo.insertOne({location:{path:'101149', target:457}})
MongoServerError: E11000 duplicate key error collection: test.foo index: location.path_1_location.target_1 collation: { locale: "en_US", caseLevel: false, caseFirst: "off", strength: 1, numericOrdering: false, alternate: "non-ignorable", maxVariable: "punct", normalization: false, backwards: false, version: "57.1" } dup key: { location.path: "0x141214141a24", location.target: 457 }