Mongoose sub-documents and _id

23 views
Skip to first unread message

Ivan Longin

unread,
Oct 25, 2014, 9:34:12 AM10/25/14
to mongoos...@googlegroups.com
Hi!

I am wondering does mongoose always create _id for sub-documents (documents in array of parent document) even if sub-document is not added as Schema object, rather as pure JSON object.
Example:

// please notice that email object is not Schema, it is normal JSON.
var email = {
    address
: { type : String }
}


var User = mongoose.Schema({
    name
: { type : String},
    lastname
: { type : String},
   
emails : [email]
})



I know that if I create email sub-document also with Schema that each email in array will have _id, but even if I create it without Schema (like in example above) mongoose still create _id for each email in array. 
So does mongoose always create _id for objects in array and is there any way to say mongoose not to create it.

Thanks.
Reply all
Reply to author
Forward
0 new messages