【发布时间】:2016-01-06 19:30:00
【问题描述】:
我正在使用 MEAN 堆栈并在 Mongoose 中编写这些方法。我想知道我放在猫鼬模型文件中的内容有什么问题。我想使用 Mongoose 简单地打印出 myModel 集合中所有文档的列表。
myModel.methods.myMethod = function(cb){
this.model("Bids").find({}, 'myField', function(err, results){
if (err){console.log(err);return err;}
console.log("okay");
console.log(results);
})
this.save(cb);
}
另外,我可以在 Mongoose 中编写什么代码来判断 myModel 集合是否为空?
授人以鱼不如授人以渔……
因此,如果您能建议我可以安装哪些调试工具(例如 Express 中间件)来帮助我自己调试,那将非常有帮助。 Please post your debugging suggestions here.
【问题讨论】:
-
find()的第二个参数是String?你确定吗?看起来很腥 -
我从Mongoose docs得到它
标签: javascript node.js mongodb mongoose mean-stack