如何在webstorm中更新警告?
我一直在开发NodeJS应用程序,它使用mongodb操作静态数据。我正在使用webstorm作为我的主编辑器程序 我编写了一个使用mongodb查找数据的函数。实际上,这是mongodb入门文档中的示例代码如何在webstorm中更新警告?,webstorm,deprecated,Webstorm,Deprecated,我一直在开发NodeJS应用程序,它使用mongodb操作静态数据。我正在使用webstorm作为我的主编辑器程序 我编写了一个使用mongodb查找数据的函数。实际上,这是mongodb入门文档中的示例代码 var findRestaurants = function(db, callback) { var cursor =db.collection('restaurants').find( ); cursor.each(function(err, doc) {
var findRestaurants = function(db, callback) {
var cursor =db.collection('restaurants').find( );
cursor.each(function(err, doc) {
assert.equal(err, null);
if (doc != null) {
console.dir(doc);
} else {
callback();
}
});
};
在第三行中,each
是mongodb驱动程序api中定义的游标对象的方法。这个方法对返回的记录操作回调函数,光标指向这些记录,并且运行此代码没有问题
但是,在webstorm编辑器窗口中,程序会向每个方法发出警告,表示此符号已弃用。它说javascript已经弃用了每个方法。webstorm似乎不知道node js或mongodb的api信息。当然,我可以忽略这个消息,但它让我有点恼火
有没有办法更新webstorm程序的警告信息?我认为有一种方法可以将节点js或mongodb api列表注册到webstorm程序,但我无法通过搜索找到它
谢谢。我也遇到了同样的问题,我发现它是对javascript.each()方法的引用,事实上该方法已被弃用。解决此问题的最简单(读取快速修复)方法是在给出错误的行上方放置“//noinspection JSDeprecatedSymbols”。您也可以单击左侧的灯泡图标,转到“不推荐使用的Javascript符号选项”,然后抑制for语句(或您可能希望用于禁用此警告的任何其他选项)
我查看了Node.JS的MongoDB引擎中的函数列表。有两个函数可以替换“each”函数:“next”和“hasNext”
因此,对于您的示例,我将编写以下代码:
var findRestaurants = function(db, callback) {
var cursor = db.collection('restaurants').find( );
var parseRestaurant = function() {
cursor.next(function(err, restaurant){
if (err)
return console.error(err);
console.dir(doc);
hasNextRestaurant();
});
};
var hasNextRestaurant = function() {
cursor.hasNext(function(err, result){
if (err)
return console.error(err);
if (result)
parseRestaurant();
else {
//Here is the last point of iterations
//We can use this for statistics output
return console.log('That\'s all');
}
});
};
hasNextRestaurant();
}
或者像这样:
var findRestaurants = function(db, callback) {
var cursor = db.collection('restaurants').find( );
var parseRestaurant = function(err, doc) {
if (err)
return console.error(err);
console.dir(doc);
cursor.hasNext(checkNext);
};
var checkNext = function(err) {
if (err)
return console.error(err);
if (result)
parseRestaurant();
else {
//Here is the last point of iterations
//We can use this for statistics output
return console.log('That\'s all');
}
cursor.next(parseRestaurant);
};
cursor.hasNext(checkNext);
}
我看不到此代码显示任何警告。这个错误看起来像什么?
var findRestaurants = function(db, callback) {
var cursor = db.collection('restaurants').find( );
var parseRestaurant = function(err, doc) {
if (err)
return console.error(err);
console.dir(doc);
cursor.hasNext(checkNext);
};
var checkNext = function(err) {
if (err)
return console.error(err);
if (result)
parseRestaurant();
else {
//Here is the last point of iterations
//We can use this for statistics output
return console.log('That\'s all');
}
cursor.next(parseRestaurant);
};
cursor.hasNext(checkNext);
}