nodejs如何用mongoose从已存在的collection中取出文档记录
发布于 12 年前 作者 nodemongodb 8011 次预览 最后一次回复是 12 年前 来自
testdb中有messages这个集合,但是find不出数据:
var mongoose = require(‘mongoose’); var db = mongoose.createConnection(‘mongodb://user:psaawd@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); });
5 回复
没有err,没有任何输出。就算不是array type也该输出点什么吧
@nodemongodb
i think the module no run.
@brighthas 能说的详细点吗
use need give all code.