I am attempting to connect to MongoDB via the package mongoose, but get an error along the lines of MongoError: database name must be a string.
I am using Windows, within the script I am also connecting to 2 other APIs which are both connected. I have tried adding my database name when requiring mongoose and also when connecting (.MyDatabaseName to the end).
Mongoose.connect("mongodb+srv://MyUserName:[email protected]", {useNewUrlParser: true}).EternalsMilitary;
Mongoose.connect.once("open", function() {
console.log("Connected To MongoDB");
}).on("error", function(err) {
console.log("Error Connecting To MongoDB: ", err);
});
It's expected to output connected, but it errors with MongoError: database name must be a string.
mongoose.connect('mongodb+srv://MyUserName:[email protected]/', {dbName: 'yourDbName'});Adding the dbname since you're using the mongodb+srv syntax