代码
var mongoose=require("mongoose");
mongoose.connect('mongodb://127.0.0.1:27017/test');//连接数据库
var connection=mongoose.connection;
connection.on('error',function(err){
if(err){
console.log(err);
}
});
connection.on('open',function(){
console.log('opened');
});
问题
(node:148572) 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/connections.html#use-mongo-client
opened
解决
还是能出来结果的,只不过是版本更新了,连接方式有变。
改成这样就行
mongoose.connect('mongodb://127.0.0.1:27017/test',{useMongoClient: true});//连接数据库
总结
刚开始看到问题所在,点进去看了mongoose的文档,无奈英文文档看不下去。于是就百度了……
还是要耐下心来看英文文档