testdb中有messages这个集合,但是find不出数据:
var mongoose = require(‘mongoose’); var db = mongoose.createConnection(‘mongodb://user:psaawd[[[[[[[[[[[@localhost](/user/localhost)](/user/localhost)](/user/localhost)](/user/localhost)](/user/localhost)](/user/localhost)](/user/localhost)](/user/localhost)](/user/localhost)](/user/localhost)](/user/localhost):27017/testdb’);
db.on('error’, console.error.bind(console, ‘connection error:’)); db.once('open’, function callback () { console.log(“connection success!”); });
var out = mongoose.model('messages’, mongoose.Schema({ name: String}), ‘messages’); out.find({}, function(err, data) { console.log(err, data, data.length); });
out.find({}, function(err, data) {
// have err?
// data is array type ?
});
签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3