I have a simple collection of users, inside which right now there are only 2 documents.
{ "_id": ObjectId("4ef8e1e41d41c87069000074"), "email_id": { "0": 109, "1": 101, "2": 64, "3": 97, { "_id": ObjectId("4ef6d2641d41c83bdd000001"), "email_id": { "0": 109, "1": 97, "2": 105, "3": 108,
now, if I try to create a new index with {unique: true} in the email_id field, mongodb will contact me with "E11000 duplicate key error index: db.users. $ email_id dup key: {: 46}". I get the same error even after specifying {dropDups: true}, however I donβt think this is the case here, since both documents have different email identifiers.
I'm not sure what is going on here, any pointers would be very appreciated.
Edit: full view of documents:
{ "_id": ObjectId("4ef8e1e41d41c87069000074"), "email_id": { "0": 109, "1": 101, "2": 64, "3": 97, "4": 98, "5": 104, "6": 105, "7": 110, "8": 97, "9": 118, "10": 115, "11": 105, "12": 110, "13": 103, "14": 104, "15": 46, "16": 99, "17": 111, "18": 109 } }
and
{ "_id": ObjectId("4ef6d2641d41c83bdd000001"), "email_id": { "0": 109, "1": 97, "2": 105, "3": 108, "4": 115, "5": 102, "6": 111, "7": 114, "8": 97, "9": 98, "10": 104, "11": 105, "12": 110, "13": 97, "14": 118, "15": 64, "16": 103, "17": 109, "18": 97, "19": 105, "20": 108, "21": 46, "22": 99, "23": 111, "24": 109 } }
There are a few more fields, such as "display_name", "registered_since", etc. that I skipped from the screen above (I don't think they play any role in the error, if you still need them, I I can probably insert all the documents here)
I am using the erlang mongodb driver to communicate with my mongo instance. All fields that can be seen are stored as binary bytes, so you see such a strange email_id in the document.
Note. The binary byte format is not forced by my code logic, I skip the email_id line very much inside my bson docs, but always get my data as binary bytes. (Probably because, as the erlang mongodb driver was written, I really did not investigate this, since my find (), find_one () and other queries work as expected, even with fields stored as binary bytes)
Edit:> db.users.findOne ()
{ "_id" : ObjectId("4ef6d2641d41c83bdd000001"), "email_id" : [ 109, 97, 105, 108, 115, 102, 111, 114, 97, 98, 104, 105, 110, 97, 118, 64, 103, 109, 97, 105, 108, 46, 99, 111, 109 ], "display_name" : [ 65, 98, 104, 105, 110, 97, 118, 43, 83, 105, 110, 103, 104 ], "provider" : [ 106, 97, 120, 108, 46, 105, 109 ], "provider_id" : [ ] }