Wonder: Is MongoDB _id unique by default?

All documents contain an _id field. All collections (except for capped ones) automatically create unique index on _id.

Try this:

db.system.indexes.find()

ok .. short version

YES YES YES

_id uniqid by default , mongoDB creates index on _id by default and you do not need any settings


According to MongoDB's manual the answer is yes, it's unique by default:

MongoDB creates the _id index, which is an ascending unique index on the _id field, for all collections when the collection is created. You cannot remove the index on the _id field.

Tags:

Mongodb