Mongoose populate Mongoose populate mongodb mongodb

Mongoose populate


Your variable OwnedTagSchema must be defined before you use it or you'll end up doing basically this:

var MovieSchema = new Schema({  title: String,  tags: [undefined]});

Move it above MovieSchema definition.


I would expect your code to work, too. Does it work if you put the OwnedTag right in MovieSchema, like so?

var MovieSchema = new Schema({  title: String,  tags: [{           _name: {type: Schema.ObjectId, ref: 'Tag'},           _owner: {type: Schema.ObjectId, ref: 'User'}        }]});

edit:

var MovieSchema = new Schema({  title: String,  tags: [{ type: Schema.ObjectId, ref: 'OwnedTag' }]});