嗨,我正在尝试建立一个简单的连接
mongoose.connect('mongodb://JFalcon:[email protected]:19476/hidonshabat', {useMongoClient: true}, function(err){
if(err) {
console.log('Some problem with the connection ' +err);
} else {
console.log('The Mongoose connection is ready');
}
})
如你所见,这是网址!请帮我
请更正如下
mongoose.connect('mongodb://<dbuser>:<dbpassword>@ds119476.mlab.com:19476/hidonshabat',
{useNewUrlParser: true },function(err)=>{
{
if(err) {
console.log('Some problem with the connection ' +err);
} else {
console.log('The Mongoose connection is ready');
}
})
mongoose.connect('mongodb://localhost:27017/myapp', **{useNewUrlParser: true}**);
来自官方文档:
useNewUrlParser - 底层的MongoDB驱动程序已弃用其当前的连接字符串解析器。因为这是一个重大更改,所以他们添加了useNewUrlParser标志,以允许用户在新解析器中发现错误时回退到旧解析器。你应该设置useNewUrlParser:true,除非这会阻止你连接。请注意,如果指定useNewUrlParser:true,则必须在连接字符串中指定端口,例如mongodb:// localhost:27017 / dbname。新的url解析器不支持没有端口的连接字符串,例如mongodb:// localhost / dbname。
var Mongoose=require("mongoose");
var dbURI='mongodb://JFalcon:[email protected]:19476/hidonshabat';
Mangoose.connect(dbURI,function(err){
if(err){
console.log('Some problem with the connection ' +err)
}
else {
console.log('The Mongoose connection is ready')
}
})
module.exports={Mongoose};