Connect to Mlab with mongoose
Asked Answered
H

3

5

Hi i'm trying to make a simple connection

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');
    }
})

As you can see this is the url! Please help me

Hemicycle answered 23/11, 2017 at 12:43 Comment(4)
What's the error???Kester
wrong credentials?Polynices
So, what is the problem? Also, when you post questions like this remember to remove your password from the connection string ie john2522 in this case :D.Calfskin
It just for test. But ty The problem is ailed to load resource: the server responded with a status of 502 (Bad Gateway)Hemicycle
E
5

Please correct as follows

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');
        }
    })
Eyeful answered 6/11, 2018 at 19:2 Comment(0)
P
1
mongoose.connect('mongodb://localhost:27017/myapp', **{useNewUrlParser: true}**);

From official docs:

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.

Paramnesia answered 12/2, 2019 at 18:8 Comment(0)
V
0
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};
Verbality answered 20/11, 2018 at 7:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.