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'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

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