After removing Mongoose-package and re-installing it again I got stuck with an error.
The error I get seems to conflict with the instruction on Mongo DB Atlas instruction. where to place username and password in the dbURI.
error:
MongoParseError: credentials must be an object with ‘username’ and ‘password’ properties
This is my connection:
const dbURI = "mongodb+srv://admin:[email protected]/myApp?retryWrites=true&w=majority"
const options = {
auth: { authSource: 'admin'},
useUnifiedTopology: true,
useNewUrlParser: true,
}
mongoose.set('strictQuery', false);
mongoose.connect(dbURI, options)
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log(err))
The error indicates to place the username and password to the option object
I use node v 19.3 and Mongoose 6.8.2.
2
Answers
According to the official Mongoose documents these are options-object.
You don’t need to specify the username and the password in the connect method of mongoose since it has already been inserted in the URL itself. In another way, there is no need to add any options when connecting to your Atlas.
Here is an example: