Mongodb 错误显示行号和文件名
Mongodb error show line number and filename
从 mongodb 节点本机驱动程序 2.x 升级到 3.x
后出现这样的错误
Third parameter to find() must be a callback or undefined
我知道该怎么做我只需要知道它在哪个文件中。如何配置驱动程序以在出现错误时显示文件/行?
阅读这篇文章 - http://thecodebarbarian.com/using-monogram-to-upgrade-from-mongodb-node-driver-2-to-3.html
您需要做的是添加会抛出异常和堆栈跟踪的中间件
db.collection('Test').pre(/^(find|findOne)$/, action => {
const opts = action.params[1];
const allowedOptions = ['projection', 'sort', 'skip', 'limit', 'hint'];
if (opts != null &&
Object.keys(opts).find(option => !allowedOptions.includes(option))) {
throw new Error('MongoDB driver 3.x does not allow passing projection ' +
'as 2nd arg to find(). Use `projection` instead. Got ' +
require('util').inspect(opts));
}
});
从 mongodb 节点本机驱动程序 2.x 升级到 3.x
后出现这样的错误Third parameter to find() must be a callback or undefined
我知道该怎么做我只需要知道它在哪个文件中。如何配置驱动程序以在出现错误时显示文件/行?
阅读这篇文章 - http://thecodebarbarian.com/using-monogram-to-upgrade-from-mongodb-node-driver-2-to-3.html
您需要做的是添加会抛出异常和堆栈跟踪的中间件
db.collection('Test').pre(/^(find|findOne)$/, action => {
const opts = action.params[1];
const allowedOptions = ['projection', 'sort', 'skip', 'limit', 'hint'];
if (opts != null &&
Object.keys(opts).find(option => !allowedOptions.includes(option))) {
throw new Error('MongoDB driver 3.x does not allow passing projection ' +
'as 2nd arg to find(). Use `projection` instead. Got ' +
require('util').inspect(opts));
}
});