Are mongodb ids unique ?

Are mongodb ids unique ?

The uniqueness constraint for _id (ObjectID) is per collection and _id (ObjectID) has to be unique in a collection, so YES! - One and the same ObjectID can occur once per collection.

This is happening you would have to manually insert duplicate ObjectID.

You can quickly verify this _id (ObjectID) by inserting two documents with the same _id (ObjectID) in two different collections.


For example, you can do it with

var id="_id"; docs = {...};  docs[id] = value;


ANIL SINGH

Hey! I am Anil Singh. I am Active Blogger, Writer and Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
http://www.code-sample.com
http://www.code-sample.xyz

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.