.net - C# MongoDB index causes weird duplicate exceptions -


we have problem our indexes. have index on our emails throws errors such:

> db.user.insert({email: "hell33o@gmail.com", "_id" : bindata(3,"ikyq6fvbcdd54tdxxx0jha==")})  writeresult({ "ninserted" : 0, "writeerror" : {     "code" : 11000,     "errmsg" : "e11000 duplicate key error index: placetobe.user.$email_text dup key: { : \"com\", : 0.6666666666666666 }" } 

})

when have index created our c# driver this

created c# with:

createindexoptions options = new createindexoptions {unique = true};         _collection.indexes.createoneasync(builders<user>.indexkeys.text(_ => _.email), options); 

resulted in

{     "v" : 1,     "unique" : true,     "key" : {         "_fts" : "text",         "_ftsx" : 1     },     "name" : "email_text",     "ns" : "placetobe.user",     "weights" : {         "email" : 1     },     "default_language" : "english",     "language_override" : "language",     "textindexversion" : 2 } 

but if create mongodb console works:

{     "v" : 1,     "unique" : true,     "key" : {         "email" : 1     },     "name" : "email_1",     "ns" : "placetobe.user" } 

i don't understand difference between 2 indexes, have effect on our db. have problems collectin saves names. duplicate exceptions on "molly" if try insert "molli". emails seems give errors whenever have 2 "gmail" emails in collection or 2 ".com" emails etc.

this university project , have turn in tomorrow. we're in trouble, appreciated

you don't want email text index. text indices allow search large amounts of text in mongodb if parsing through comments or something. want make sure emails aren't duplicated should use ascending or descending index.

createindexoptions options = new createindexoptions {unique = true};     _collection.indexes.createoneasync(builders<user>.indexkeys.ascending(_ => _.email), options) 

Comments