person 集合中有 3 个文档,但我找不到()
蒙哥贝壳:
> use test;
switched to db test
> db.person.find();
{ "_id" : ObjectId("527f18f7d0ec1e35065763e4"), "name" : "aaa", "sex" : "man", "height" : 180 }
{ "_id" : ObjectId("527f1903d0ec1e35065763e5"), "name" : "bbb", "sex" : "man", "height" : 160 }
{ "_id" : ObjectId("527f190bd0ec1e35065763e6"), "name" : "ccc", "sex" : "woman", "height" : 160 }
我的nodejs代码:
var mongoose = require('mongoose');
var db = mongoose.createConnection('mongodb://uuu:ppp@localhost:27017/test');
//mongoose.set('debug', true);
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback () {
console.log("connection success!");
mongoose.model('person', mongoose.Schema({ name: String}),'person');
var out = db.model('person');
//console.log(out);
out.find({},function(err, obj) {
console.log(obj);
console.log(1);
});
});
但是,结果是:连接成功![] 1