【发布时间】:2019-10-05 11:28:02
【问题描述】:
我正在尝试获取 MongoDB 集合中 documents 的计数,但我没有得到计数。
这是我正在尝试的:
//get the invoice count
Routes.route('/invoicescount').get((req, res) => {
invoicesDB.count({}, (err, count) => {
if (err) {
res.status(400).send(err);
} else {
const c = count;
res.status(200).send(c);
}
});
});
它没有给出任何值,但在控制台中它给出了这个错误:
发现错误:CastError: Cast to ObjectId failed for value 模型“invoices”的路径“_id”中的“invoicescount”
【问题讨论】:
标签: javascript node.js mongodb express