Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js mongoose连接中的DeprecationWarning,尽管将其设置为true_Node.js_Mongodb_Mongoose - Fatal编程技术网

Node.js mongoose连接中的DeprecationWarning,尽管将其设置为true

Node.js mongoose连接中的DeprecationWarning,尽管将其设置为true,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我收到了这些反对的警告,尽管我认为我应该传递这些论点,但我不知道为什么。我有一个mongoose连接配置文件设置,它似乎不起作用 const mongoose = require('mongoose'); const config = require('config'); const db = config.get('mongoURI'); mongoose.connect(db); const connectDB = async () => { try {

我收到了这些反对的警告,尽管我认为我应该传递这些论点,但我不知道为什么。我有一个mongoose连接配置文件设置,它似乎不起作用

const mongoose = require('mongoose');
const config   = require('config');
const db       = config.get('mongoURI');

mongoose.connect(db);

const connectDB = async () => {
    try {
        await mongoose.connect(db, {
            useNewUrlParser: true,
            useCreateIndex: true,
            useFindAndModify: false,
            useUnifiedTopology: true
        });
        
        console.log("Mongoose database connected");
    }
    catch(error){
        console.log(error);
        // Exit program with error
        process.exit(1);
    }
}

module.exports = connectDB;
这里有我遗漏的东西吗?即使以这种方式设置文件,我仍会收到以下错误:

(node:9464) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
Server initialized on port 5000
(node:9464) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
Mongoose database connected
谢谢你。

你在打电话吗

mongoose.connect(db);
没有提供任何选择。该呼叫可能会生成您所看到的警告。

您正在呼叫

mongoose.connect(db);

没有提供任何选择。该调用可能会生成您看到的警告。

链接到您正在遵循的文档?我在此处使用文档,但可能执行不正确:链接到您正在遵循的文档?我在此处使用文档,但可能执行不正确: