N
N
narem2019-09-26 17:44:48
MongoDB
narem, 2019-09-26 17:44:48

How to connect to mlab correctly?

I'm trying to connect to m lab
I'm writing

mongoose.connect('mongodb+srv://Yri:***@cluster0-0n7so.mongodb.net/test?retryWrites=true&w=majority', {useMongoClient: true});

I specify the correct password accordingly - it gives me an error
[Error: Invalid mongodb uri "mongodb+srv://Yri:[email protected]/test?retryWrites=true&w=majority". Must begin with "mongodb://"]
[nodemon] app crashed - waiting for file changes before starting...

I change start to mongodb:// and gives another error
{ [MongoError: failed to connect to server [cluster0-0n7so.mongodb.net:27017] on first connect [MongoError: getaddrinfo ENOTFOUND cluster0-0n7so.mongodb.net cluster0-0n7so.mongodb.net:27017]]
name: 'MongoError ',
message: 'failed to connect to server [cluster0-0n7so.mongodb.net:27017] on first connect [MongoError: getaddrinfo ENOTFOUND cluster0-0n7so.mongodb.net cluster0-0n7so.mongodb.net:27017]' }
[nodemon ] app crashed - waiting for file changes before starting...

I specify the correct login and password from the database - I use them to connect via Robo 3T - everything is OK

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hzzzzl, 2019-09-26
@hzzzzl

you have some strange link to mlab, I have ALL links to mlab of this kind
mongodb://USER:[email protected]:29780/DBNAME
link from here?
5d8cd14a320ef765976197.png

G
grinat, 2019-09-26
@grinat

Show the node_modules/mongodb/lib/url_parser.js file, I don’t find the Must begin with line in mine at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question