Throw clean error in `openUri()` if uri is `undefined`
See original GitHub issueDo you want to request a feature or report a bug?
I am trying to get a failing service back up and running. After updating to mongoose@5.2.5
I get the following error message:
UnhandledPromiseRejectionWarning: MongoParseError: URI malformed, cannot be parsed
I’m using mLab so my connection string looks like:
mongodb://<user>:<password>@ds227525.mlab.com:27525/dbname
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
auth: {
user: process.env.MONGO_USER,
password: process.env.MONGO_PASSWORD
}
})
My question is does auth.user
and auth.password
get injected into the user/password part of the connection string? Everything I’m trying is still yielding the error message
node 8.11.1 mongoose 5.2.5 mongoDb 4.0.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:8
Top Results From Across the Web
The `uri` parameter to `openUri()` must be a string, got ...
When I run my project, I get this error: /home/ali/Desktop/personalitytest-backend/node_modules/mongoose/lib/connection.js:428 throw new ...
Read more >Mongoose v6.8.2: API docs
If bufferCommands is true, Mongoose will throw an error after bufferTimeoutMS if the operation is still buffered. [options.dbName] «String» The name of the ......
Read more >MongooseError: The `uri` parameter to `openUri()` must be a ...
This error originated either by throwing inside of an async ... The `uri` parameter to `openUri()` must be a string, got "undefined".
Read more >Top 10 errors from 1000+ Ruby on Rails projects ... - Rollbar
Table of Contents. Here are the top 10 Rails errors: 1. ActionController::RoutingError; 2. NoMethodError: undefined method '[]' for nil: ...
Read more >Uri | Android Developers
Behavior is undefined for invalid input. This class is very forgiving--in the face of invalid input, it will return garbage rather than throw...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It seems like the value of
process.env.MONGO_URI
in your production environment is different from the one in your development environment, possibly being null or undefined.Have you tried inspecting (console.info, etc ) the value of
process.env.MONGO_URI
in your production environment right before it’s passed intomongoose.connect()
?Something like the following would ensure it’s set properly before trying to connect:
What you are seeing can be replicated by explicitly passing null or undefined (basically anything that isn’t a string, ie
{}
or42
) as the first argument tomongoose.connect()
. All of these values have the same output asnull
below:6763.js
output:
Mongoose’s connection code will potentially set connection options based on the connection string, but mongoose doesn’t mutate the string based on the options ( or in any way that I’m aware of ).
Just to be sure, I tested mongoose 5.2.5 with my MLab test account and it works without error for me:
6763.js
Output:
I included the toString() value of sharable to show how I’m mutating my connection string when I print it out here
Feel free to join us on either Gitter.im or Slack to chat about it in real time.
@chriselliott82 that’s the new error message that we added. Please read me the error message and make sure you aren’t calling
mongoose.connect()
with no parameters.