I'm surprised to see that the _id
is not a unique index. I'm providing values for the _id
field and MongoDB is creating an index alright but it's not unique. I tried to update it (by creating a new unique index on the _id
field) but nothing changed. I didn't get any error either. Why is this happening and how can I make a unique index on _id
?
MongoDB version (as given by version()
) 3.0.6, Casbah version 2.8.2, Scala version 2.11.7.
My document structure:
{_id=1, firstName=John, lastName=Doe, phoneNum=111-111-1111, active=true, email=test@gmail.com}
Indices as dumped in the logs (timestamp etc. omitted for brevity). I'm not sure why each index is printing twice but that's an issue for another question. For the records, this is how I'm printing the indices: collection.indexInfo.foreach { index => logger.debug(s"Index: ${index.toMap}") }
Index: {v=1, key={ "_id" : 1}, name=_id_, ns=akka.users}
Index: {v=1, unique=true, key={ "phoneNum" : 1}, name=phoneNum_1, ns=akka.users}
Index: {v=1, unique=true, key={ "email" : 1}, name=email_1, ns=akka.users, sparse=true}
Index: {v=1, key={ "_id" : 1}, name=_id_, ns=akka.users}
Index: {v=1, unique=true, key={ "phoneNum" : 1}, name=phoneNum_1, ns=akka.users}
Index: {v=1, unique=true, key={ "email" : 1}, name=email_1, ns=akka.users, sparse=true}