I have a mongo database named teps
in which I have created a user with read/write access and secured it with password. Earlier before creating the user, I had been connecting to the db with MongoClient
like this:
var MongoClient = require("mongodb").MongoClient;
const client = new MongoClient('mongodb://localhost:27017/', {
useUnifiedTopology: true,useNewUrlParser: true
});
const db = client.db("teps");
But after creating the user, I have below connection string :
var conn = "mongodb://USERTEPS:teps_passwd@localhost:27017/?authMechanism=DEFAULT&authSource=teps"
The problem is I don't understand how can I use above string in my existing code to connect to db. I tried putting this string directly inside MongoClient
constructor, but the database didn't connect.
Can someone help me identifying the correct way to connect to my db using the existing code only.
Thank You!