【发布时间】:2011-11-07 00:47:47
【问题描述】:
我的代码是这样的:
SiteModel.find(
{},
function(docs) {
next(null, { data: docs });
}
);
但它从不返回任何内容...但是如果我在 {} 中指定某些内容,则只有一条记录。那么,怎么找到呢?
【问题讨论】:
我的代码是这样的:
SiteModel.find(
{},
function(docs) {
next(null, { data: docs });
}
);
但它从不返回任何内容...但是如果我在 {} 中指定某些内容,则只有一条记录。那么,怎么找到呢?
【问题讨论】:
试试这段代码来调试:
SiteModel.find({}, function(err, docs) {
if (!err) {
console.log(docs);
process.exit();
}
else {
throw err;
}
});
【讨论】:
node filename.js这样的终端运行它时这不起作用?
then-catch 之类的范例,您甚至不需要空花括号。
const result = await SiteModel.find() - 在.find() 函数中没有{} 也可以。
【讨论】:
let result = SiteModel.find({}, function (err, docs) {});
或者使用 async await 你也可以这样做:
let result = await SiteModel.find({});
【讨论】:
2017 节点 8.5 方式
try {
const results = await SiteModel.find({});
console.log(results);
} catch (err) {
throw err;
}
【讨论】: