简体   繁体   中英

MongoDB DaaS: Remote connection string seems to result in local lookup

I am interested in trying out DaaS services to use MongoDB with my Node/Express app in production but am having trouble connecting.

With both Compose and mLab, I am able to successfully connect to the remote server's mongo console, but when I attempt to connect using Mongoose using a connection string along the lines of:

mongoose.connect('mongodb://user:pass@server.compose.io:port_name/db_name');

or

mongoose.connect('mongodb://<dbuser>:<dbpassword>@ds012345.mlab.com:56789/mydb');

in my app, I receive the following error:

MongoError: failed to connect to server [localhost:27017] on first connect at null.

Using a different machine, I successfully connected to mLab using the app that I am developing, so I feel confident that a) the app - which as far as setup goes is pretty much express generator boilerplate - is not set up in a way that would prevent the connection and b) there is not a basic issue here like a mistyped connection string.

I'm posting this to see if there is something to do with my Node environment or perhaps something related to the network setup of the computer that I'm using that I should consider to enable my app to again connect to a remote MongoDB database for testing during development.

Many thanks in advance for your help.

I'd check your code to ensure you aren't racing the reading of a connection string and don't have a "mongoose.connect()" somewhere in your code. That error is more indicative of connect() being called with no parameters or with null and using its default settings (IME any other malformation of URL tends to produce a specific error).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM