"Calling an asynchronous function without callback is deprecated." 但是有回调

"Calling an asynchronous function without callback is deprecated." But there is a call back

我有一个函数可以根据数据库中的文档处理引脚的开关状态。这个函数使用了很多库,我相信其中一个导致了弃用(根据我在代码片段下方包含的弃用跟踪,我认为它是 Raspberry PI 的 OnOff Gpio 库)。哪个功能导致弃用?回滚 Node 更新的缺点是什么?我真的很想听听对此的一些意见,提前谢谢你。


MongoClient.connect(url, function (err, db) {
    if (err) {
        console.log('Unable to connect to the mongoDB server. Error:', err);
    } else {
        var collection = db.collection('re');//change as needed
        collection.findAndModify(
        {"restart":"sensor","value":false},
        {},
        {"$set":{"value":true}},
        {},
        function(err,result){
            if(err){
                throw err;
            }
            else{
                console.log(result);
                if(result.value!=null){
                    spin.write(0);
                    setTimeout(function() {
                        spin.write(1);
                    },10000);
                }
                else{
                    console.log("Sensor should stay on");
                    spin.write(1);
                }
            }
        });


    }
    db.close();
});

(node:10503) DeprecationWarning: Calling an asynchronous function without callback is deprecated.

at maybeCallback (fs.js:98:42)

at Object.fs.write (fs.js:703:16)

at Gpio.write (/home/pi/node_modules/onoff/onoff.js:190:6)

at Object. (/home/pi/local-opio/final:16:6)

at Module._compile (module.js:571:32)

at Object.Module._extensions..js (module.js:580:10)

at Module.load (module.js:488:32)

at tryModuleLoad (module.js:447:12)

at Function.Module._load (module.js:439:3)

at Module.runMain (module.js:605:10)

at run (bootstrap_node.js:422:7)

at startup (bootstrap_node.js:143:9)

at bootstrap_node.js:537:3

您似乎对 onoff 包的 write function 进行了 3 次调用,但没有可选的回调。尝试将适当的回调(采用 err 参数)传递给每个调用。