首页 > 解决方案 > Error with using mongoose package for connection

问题描述

DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser...

{ useUnifiedTopology: true },
{ useNewUrlParser: true }

标签: node.jsmongodbmongoose

解决方案


It's because every option passed should be one object like this

{ useUnifiedTopology: true ,
 useNewUrlParser: true }

Full Connection could be like

 mongoose.connect(URL, {
    useUnifiedTopology: true ,
    useNewUrlParser: true
}
).then(() => {
    console.log('Successfully connected to the database');
}).catch(err => {
    console.log(`Could not connect to the database.. ${err}`);
    process.exit();
});

推荐阅读