1
我正在使用mongo在Express中开发应用程序。我必须检查集合中是否存在特定的文档。我这样做:快速:查询以检查文档是否存在
router.route('/').post(function (req, res, next) {
var name = req.body.name;
var dept = req.body.dept;
var arr = mongoose.model('User').find({'name': name, 'dept': dept});
if(arr.length() > 0){
//do something
}
}
是什么mongoose.model('User').find({'pemail': email, 'password': password});
实际上返回,因为当我运行的应用程序,它给了我这个错误:
TypeError: undefined is not a function
任何帮助吗?
你需要'里面找到(回调函数)'。看看这里的正确语法:http://mongoosejs.com/docs/queries.html – Hamed
更好的是'.findOne()',但我认为你甚至没有将'mongoose'导入到本地作用域通过'require'。加上已经提到的回调。 –
谢谢@Hamed,这是做的工作,请把它作为答案在这里... – Saani