mongoose 连接成功,但是发出警告,好像是新版本要修改哪?错误信息如下
DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0,use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`
网上找了半天没有结果,求答案,附上连接代码
var mongoose = require('mongoose')
mongoose.connect('mongodb://localhost/test');
var db = mongoose.connection
db.on('error', console.error.bind(console, '连接错误:'));
db.once('open', function() {
console.log('连接成功');
})
加个{useMongoClient:true}
比如
mongoose.connect('mongodb://localhost/test',{useMongoClient:true})
就可以了,
我是查看:
http://mongoosejs.com/docs/co...
拉下来最后页的The
useMongoClient
Option才知道的