I need to setup Mongo DB with my nodejs application . I created an account in mongoDb Atlas and I am trying to connect my app with the below URL with my username and password . Unfortunately I am getting authentication Fail error .
const MongoClient = require("mongodb").MongoClient;
const CONNECTION_URL = "mongodb+srv://<username>:<password>@renj0-2herp.mongodb.net/test?retryWrites=true";
const DATABASE_NAME = "example";
var app = Express();
app.use(BodyParser.json());
app.use(BodyParser.urlencoded({ extended: true }));
var database, collection;
app.post("/person", (request, response) => {
collection.insert(request.body, (error, result) => {
if(error) {
return response.status(500).send(error);
}
response.send(result.result);
});
});
app.get("/people", (request, response) => {
collection.find({}).toArray((error, result) => {
if(error) {
return response.status(500).send(error);
}
response.send(result);
});
});
app.listen(3001, () => {
MongoClient.connect(CONNECTION_URL, { useNewUrlParser: true }, (error, client) => {
if(error) {
throw error;
}
database = client.db(DATABASE_NAME);
collection = database.collection("people");
console.log("Connected to `" + DATABASE_NAME + "`!");
});
});