CNode

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

Nnodemongodb发布于13 年前最后回复13 年前5 回复8198 浏览0 收藏

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#1·13 年前
out.find({}, function(err, data) {
    // have err?
    // data is array type ?
});

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

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

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

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

@nodemongodb

i think the module no run.


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

B
brighthas#5·13 年前

use need give all code.


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

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