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ù)庫連接成功!------");
});