I have a node.js application that is deployed on azure using CosmosDB and the MongoDB API. My application uses mongoose, which works easily in 4.13.9.
My application that works is connected as follows:
var configDB = require('./config/database'); var mongoose = require('mongoose'); mongoose.connect(configDB.url, { useMongoClient: true } ); mongoose.Promise = global.Promise; var db = mongoose.connection; db.on('error', console.error.bind(console, 'MongoDB connection error:'));
The config / database file is defined as follows (username, password, DB changed to protect the innocent):
module.exports = { 'url': 'mongodb://azureusername: azurepassword@myazuredb.documents.azure.com :10255/?ssl=true' }
Now the problem occurs when I install mongoose 5.0.1. I remove the useMongoClient parameter from the connection and get rid of the promise, so my connection code is now:
mongoose.connect(configDB.url); var db = mongoose.connection; db.on('error', console.error.bind(console, 'MongoDB connection error:'));
When this is done, I get the following in the console:
(node: 21392) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Password contains illegal unescaped character
I can even comment on the connection code where it is only mongoose.connect, and this is what gives the error. What am I doing wrong? Is there a 5.0.1 change that I need to consider? As a side note, which may or may not be related, I saw a few notes about what now gives a callback instead of using promises, so if someone has an example of how they do this in a Node / Express application, which would be great, but it doesn't look like isee when I get an error message related to an illegal character. NOTE. The configuration file is exactly the same if it works with versions 4.13.9 or 5.0.1, so I know that the password is valid and that is not a problem.