![](/img/trans.png)
[英]How to remove one of the data from output nodejs mongodb database
[英]How to take and output documents from a MongoDB database with NodeJS?
我一直在使用 NodeJS、Express 和 MongoDB 处理我的第一个 API 项目。我可以使用 collection.insertOne(newDocument) 方法将新文档保存到数据库中,但我不能使用 collection.find( 获取现有文档和 output 它们{}).
你能帮我么:')
export const visualizeUser = (req, res) => {
console.log("you are searching the user with username " + req.body.username);
users.find({username: 'yavuz'}, (err, data) => {
if(err)
console.log(err);
else
console.log(data);
});
}
那就是我写的代码。
MongoInvalidArgumentError:参数“选项”不能是 function
这就是我得到的错误。
非常感谢您的帮助。
就像错误消息所说的那样,您不能将 function 作为选项参数传递。
看这里:文档
您的代码应如下所示:
const visualizeUser = async (req, res) => {
try{
console.log("you are searching the user with username " +
req.body.username);
let data = await users.find({username: 'yavuz'});
console.log(data)
} catch(e) {
console.log(e)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.