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 _ids within the embeds unique across the collection? I was thinking of querying just using embeds._id to get the Parent if it is.
If you allow mongo to create your _id field then they will all be unique in that collection.