LearnBoost/mongoose — Issue #631: DBRefs populate doesnt work
Author: nambad
Created: 2011-11-30 12:08:20+00:00
State: open

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/commentsys');

var Schema = mongoose.Schema
, ObjectId = Schema.ObjectId;

var UserSchema = new Schema({
username: {type:String, default:'Anonymous'},
visits	: Number,
});

var PostSchema = new Schema({
_author	: { type: Schema.ObjectId, ref: 'Users'},
title	: { type:String, default:'New Title'},
body	: { type:String, default:'New Body'},
});

var Users = mongoose.model('users', UserSchema);
var Post = mongoose.model('posts', PostSchema);

Users.find({},function(err,docs){
console.log(docs); //Works fine
});

Post.find({}).populate('_author') //gives error
.run(function (err, docs) {
console.log(docs)
});

node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Schema hasn't been registered for model "Users".
Use mongoose.model(name, schema)
at Mongoose.model (/var/www/nodetest/node_modules/mongoose/lib/index.js:173:13)
at NativeConnection.model (/var/www/nodetest/node_modules/mongoose/lib/connection.js:381:27)
at model.model (/var/www/nodetest/node_modules/mongoose/lib/model.js:447:18)
at model.populate [as _populate] (/var/www/nodetest/node_modules/mongoose/lib/model.js:153:10)
at next (/var/www/nodetest/node_modules/mongoose/lib/model.js:239:14)
at next (/var/www/nodetest/node_modules/mongoose/lib/model.js:208:57)
at next (/var/www/nodetest/node_modules/mongoose/lib/model.js:208:57)
at next (/var/www/nodetest/node_modules/mongoose/lib/model.js:208:57)
at next (/var/www/nodetest/node_modules/mongoose/lib/model.js:208:57)
at next (/var/www/nodetest/node_modules/mongoose/lib/model.js:208:57)

Can anyone please help.. I am using the latest version from npm