我是mongoose的新手。我正在尝试使用mongoose从我的mongodb打印数据。 我的代码 -
mongoose.connect('mongodb://localhost/dbname');
var Schema = mongoose.Schema;
var dbSchema = new Schema({
name: String,
url: String,
category: { name: String, path: String },
});
var db = mongoose.model('db',dbSchema, 'colection_name');
console.log(db.url);
我的mongodb -
{
"name": "xxxx",
"url": "http://localhost/kayiIU9g3443",
"category" : {
"name": "yyyy",
"path": "ggggg"
},
}
答案 0 :(得分:1)
db.find(function (err, db) {
if (err) return console.error(err);
console.dir(db);
});