I want to create a new database at the time of the API call. I am already connected to one main database.
I have tried using mongoose.connect() method. And it gives me a positive response. But when I checked in mongo console I did not find the newly created database.
Here is my code.
const connectionString = `mongodb://${process.env.DB_HOST}:${
process.env.DB_PORT
}/client_${Math.random()
.toString(36)
.substring(2, 8)}`;
mongoose.connect(
connectionString,
{
autoReconnect: true,
reconnectTries: 60,
reconnectInterval: 10000,
useNewUrlParser: true,
useCreateIndex: true
},
(error) => {
if (error) {
console.log(error);
} else {
console.log('Connected');
}
}
);
Hope you got my point. Looking for a solution.