跳到主要内容
CNode

nodejs如何用mongoose从已存在的collection中取出文档记录

社区
Nnodemongodb发布于 13 年前最后回复 13 年前
582230

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)

B
brighthas#513 年前

use need give all code.


签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3

B
brighthas#313 年前
引用 brighthas签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3

@nodemongodb

i think the module no run.


签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3

N
nodemongodb#213 年前
引用 brighthas签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3

没有err,没有任何输出。就算不是array type也该输出点什么吧

B
brighthas#113 年前
out.find({}, function(err, data) {
    // have err?
    // data is array type ?
});

签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3

参与回复

登录后即可参与回复。登录