【发布时间】:2020-07-21 15:42:04
【问题描述】:
这是我的一些代码
server.get("/get", getCallback);
function getCallback(req,res) {
collection.find({}).next(findCallback);
function findCallback(err,foundRecord) {
if (err == null) {
console.log('FOUND: ' + foundRecord);
return res.status(200).send(foundRecord);
}
else
throw err;
}
}
它让我在控制台中返回{"readyState":1}。
无论我尝试什么,它都会给我不同类型的错误。 我没有问题将数据保存到集合中,但尽快 当我去把它拿出来时,没有任何效果。
【问题讨论】:
-
或许你可以试试 async/await(with driver v3) 并参考find documentation。另外请提及您正在使用的mongodb驱动api版本,因为v2和v3差异很大。
-
使用
Promise而不是callback
标签: javascript arrays node.js mongodb express