I've been trying to follow the information in Mongoose Population, but I'm getting the exception:
MissingSchemaError: Schema hasn't been registered for model "undefined".
The code I have goes like this:
mongoose = require('mongoose');
Schema = mongoose.Schema;
mongoose.connect(MONGO_SERVER);
ObjectId = Schema.ObjectId;
var FirstSchema = new Schema({
label : String
});
var SecondSchema = new Schema({
first_id : [{ type: mongoose.Schema.ObjectId, ref: 'First' }],
type : String,
// ...
});
var first= mongoose.model('First', FirstSchema);
var second= mongoose.model('Second', SecondSchema);
function test() {
// ...
second.find({}).populate('first_id').exec(function(err,data){return true;});
// ...
}
And the error occurs on the populate, I've tweaked it a number of times to different answers found on forums, and I'm sure it will be something simple, but can someone point me in the right direction?
Cheers.