mongoose 連接問題(node:3564) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0)(cms-se...

1.問題展示

image.png

代碼


var mongoose=require("mongoose");
 var dbUrl = config.URL;

mongoose.connect(dbUrl);//連接數(shù)據(jù)庫
 
mongoose.connection.on('error',function(err){
    if(err){
       console.log("數(shù)據(jù)庫連接失?。? + error);
    }
});
mongoose.connection.on('open',function(){
    console.log("------數(shù)據(jù)庫連接成功!------");
});



2.問題原因



(node:3564) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/4.x/docs/connections.html#use-mongo-client


3.解決方案

對操作沒影響,但本人有強(qiáng)迫癥
可以改成:

var mongoose=require("mongoose");
 var dbUrl = config.URL;

mongoose.connect(dbUrl,{useMongoClient: true});//連接數(shù)據(jù)庫 

mongoose.connection.on('error',function(err){
    if(err){
       console.log("數(shù)據(jù)庫連接失?。? + error);
    }
});
mongoose.connection.on('open',function(){
    console.log("------數(shù)據(jù)庫連接成功!------");
});


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容