LearnBoost/mongoose — Issue #575: EmbedDoc (single embed does not work)
Author: pmlopes
Created: 2011-10-24 10:37:05+00:00
State: open

If you have a model like:

var SingleComment = new Schema({
title : String
, body : String
, date : Date
});

var BlogPost = new Schema({
author : ObjectId
, title : String
, body : String
, buf : Buffer
, date : Date
, comment : SingleComment
, meta : {
votes : Number
, favs : Number
}
});

var Post = mongoose.model('BlogPost', BlogPost);

You get an error:

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: undefined is not a function
at CALL_NON_FUNCTION_AS_CONSTRUCTOR (native)
at Function.interpretAsType
at Schema.path
at Schema.add
at new Schema

This is a simple one-to-one (denormalized) relationship that i would like to have on my models. I don't want to copy paste the SingleComment schema to the Post schema because i would like to use validation and all the goodies (read plugins) i can add to the SingleComment Schema.

Is there a way to work around this error?