如何使用NodeJS / express JS在MongoDB中获取文档计数
我正在尝试获取documents
集合中MongoDB
的计数,但我没有得到计数。
这是我正在尝试的内容:
//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:在模型“发票”的路径“ _id”处,值“ invoicescount”的铸造到ObjectId失败。
我正在尝试获取MongoDB集合中文档的数量,但是我没有获得数量。这是我要尝试的://获取发票计数Routes.route('/ invoicescount')。get((req,res)=&...
回答如下:
如何使用NodeJS / express JS在MongoDB中获取文档计数
我正在尝试获取documents
集合中MongoDB
的计数,但我没有得到计数。
这是我正在尝试的内容:
//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:在模型“发票”的路径“ _id”处,值“ invoicescount”的铸造到ObjectId失败。
我正在尝试获取MongoDB集合中文档的数量,但是我没有获得数量。这是我要尝试的://获取发票计数Routes.route('/ invoicescount')。get((req,res)=&...
回答如下: