Last Updated: February 25, 2016
· klclee

mongoose: Cast to ObjectId failed for value "[object Object]" at path "_id"

As a newbie mongoose user this was a bit abstract for me. If you get the above error is likely that you sub document have been 'created' yet so either:

if you sub document have a sperate defined schema:

var sub_schema = mongoose.model('Sub_Schema', Sub_Schema);
var Sub = new sub_schema();

Or if your sub document is defined within the parent (version 3.x onwards):

var parent = new Parent();
var sub_doc = parent.children.create({data: 'gggg'});