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;


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 - and
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book