Reputation: 2880
I have the following Mongoose schema that embeds another:
var EmbedSchema = new Schema({
foo: String
});
var ParentSchema = new Schema({
foo: String
embeds: [EmbedSchema]
});
After instantiating and embedding a couple objects, I'll end up with something like this:
{
"_id": "4f505a866e65f3896b00002c",
"foo": "some value",
"embeds: [
{
"_id": "4f505aa36e65f3896b000034",
"foo": "some value 1"
}, {
"_id": "4f2eeb8f559757bf4f000001",
"foo": "some value 2"
}
]
}
Are the _id
s within the embeds
unique across the collection? I was thinking of querying just using embeds._id
to get the Parent
if it is.
Upvotes: 2
Views: 984
Reputation: 1468
If you allow mongo to create your _id field then they will all be unique in that collection.
Upvotes: 1
Reputation: 434965
Embedded documents are full blown documents so their _id
s are not only unique within the collection, they are globally unique.
Upvotes: 5