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

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

Are mongodb ids unique ? Are mongodb ids unique ? Reviewed by Anil Singh on 10:12 PM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^