###1. Question presentation

code

var mongoose=require("mongoose"); var dbUrl = config.URL; mongoose.connect(dbUrl); Mongoose.connection. on('error',function(err){if(err){console.log(" failed to connect: "+ error); }}); Mongoose.connection. on('open',function(){console.log("------ database connection successful! -- -- -- -- -- - "); });Copy the code

###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


Copy the code

###3. The solution does not affect the operation, but I have obsessive-compulsive disorder.

var mongoose=require("mongoose"); var dbUrl = config.URL; mongoose.connect(dbUrl,{useMongoClient: true}); Mongoose.connection. on('error',function(err){if(err){console.log(" failed to connect: "+ error); }}); Mongoose.connection. on('open',function(){console.log("------ database connection successful! -- -- -- -- -- - "); });Copy the code