node.js - 【mongoose】连接警告:`open()` is deprecated in mongoose >= 4.11.0

查看:1340
本文介绍了node.js - 【mongoose】连接警告:`open()` is deprecated in mongoose >= 4.11.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

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才知道的

这篇关于node.js - 【mongoose】连接警告:`open()` is deprecated in mongoose >= 4.11.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆