It is generally connected like this:

mongoose.connect("mongodb://username:[email protected]:27017/db");

However, if your password has special characters such as’ @ ‘or’ % ‘in it, the mongodb connection may not be properly parsed and character escapes will not work, causing the connection to fail.

There are two ways around this problem:

1. Change the connection format

mongoose.connect(
	"mongodb://username:[email protected]:27017/db",
	{user: 'username'.pass: 'password'});Copy the code

2. Enable uri_decode_Auth

Uri_decode_auth Decode connection strings inside the driver

mongoose.connect(
	"mongodb://username:[email protected]:27017/db", 
	{
  		uri_decode_auth: true
  	},
  	 function(err, db) {});Copy the code