使用 mongoose 连接到 Mlab
Connect to Mlab with mongoose
嗨,我正在尝试建立一个简单的连接
mongoose.connect('mongodb://JFalcon:john2522@ds119476.mlab.com:19476/hidonshabat', {useMongoClient: true}, function(err){
if(err) {
console.log('Some problem with the connection ' +err);
} else {
console.log('The Mongoose connection is ready');
}
})
如您所见,这是 url!
请帮助我
请更正如下
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');
}
})
var Mongoose=require("mongoose");
var dbURI='mongodb://JFalcon:john2522@ds119476.mlab.com: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};
mongoose.connect('mongodb://localhost:27017/myapp', **{useNewUrlParser: true}**);
来自官方文档:
useNewUrlParser - The underlying MongoDB driver has deprecated their
current connection string parser. Because this is a major change, they
added the useNewUrlParser flag to allow users to fall back to the old
parser if they find a bug in the new parser. You should set
useNewUrlParser: true unless that prevents you from connecting. Note
that if you specify useNewUrlParser: true, you must specify a port in
your connection string, like mongodb://localhost:27017/dbname. The new
url parser does not support connection strings that do not have a
port, like mongodb://localhost/dbname.
嗨,我正在尝试建立一个简单的连接
mongoose.connect('mongodb://JFalcon:john2522@ds119476.mlab.com:19476/hidonshabat', {useMongoClient: true}, function(err){
if(err) {
console.log('Some problem with the connection ' +err);
} else {
console.log('The Mongoose connection is ready');
}
})
如您所见,这是 url! 请帮助我
请更正如下
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');
}
})
var Mongoose=require("mongoose");
var dbURI='mongodb://JFalcon:john2522@ds119476.mlab.com: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};
mongoose.connect('mongodb://localhost:27017/myapp', **{useNewUrlParser: true}**);
来自官方文档:
useNewUrlParser - The underlying MongoDB driver has deprecated their current connection string parser. Because this is a major change, they added the useNewUrlParser flag to allow users to fall back to the old parser if they find a bug in the new parser. You should set useNewUrlParser: true unless that prevents you from connecting. Note that if you specify useNewUrlParser: true, you must specify a port in your connection string, like mongodb://localhost:27017/dbname. The new url parser does not support connection strings that do not have a port, like mongodb://localhost/dbname.