How to connect locally to mongodb from node.js

I have installed mongoDB on the same droplet as my node.js application in the root folder. But when i try to connect to my mongoDB database it is failing. It is telling me “Err too many redirects”. I am using the following line to try to connect with mongoose: mongoose.connect(“mongodb://username:password@”, {useNewUrlParser: true });

In the UFW i have allowed income on my droplet IP and 27017.

Hope one of you can tell me what is wrong.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Have you started Mongo Server?

Can you connect it through command line like?

mongo -u username -p password --authenticationDatabase admin