LearnBoost/mongoose — Issue #667: Populating an array
Author: agentcooper
Created: 2011-12-30 19:26:20+00:00
State: open

So where I am being stupid here? It throws an error "TypeError: Cannot call method 'path' of undefined".

```javascript
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;

mongoose.connect('mongodb://localhost/testy2');

var UserSchema = new Schema({
name: String
});

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

var TagSchema = new Schema({
name: String
});

var Tag = mongoose.model('Tag', TagSchema),
User = mongoose.model('User', UserSchema),
Movie = mongoose.model('Movie', MovieSchema);

User.create({name: 'Johnny'}, function(err, johnny) {
Tag.create({name: 'drama'}, function(err, drama) {
Movie.create({'title': 'Dracula', tags:[{_name: drama._id, _owner: johnny._id}]}, function(err, movie) {

// runs fine without 'populate'
Movie.findById(movie).populate('tags._name').run(function(err, movies) {
console.log(movies);
});
});
});
});
```