Reputation: 3226
I want to check that if I use _id
fields that refer to documents from different collections, I will never have a duplicate _id
, i.e. used in 2 different collections inside the same database.
Using meteor (so both in minimongo and mongodb), is the _id
field unique in its collection or in the entire database?
Upvotes: 2
Views: 194
Reputation: 34641
The _id
values you have in your database are generated by Meteor using Random.id()
. These are unique across all collections.
Please note that the uniqueness of _id
values in MonogoDB is ensured on the collection level, meaning that there is always a unique index on the _id
field for every collection. There is no MongoDB mechanism in place that would ensure _id
uniqueness across collections.
In any case, it is quite a safe assumption that Meteor's random IDs will never collide.
Upvotes: 3