How to connect locally to mongodb from node.js

April 24, 2019 677 views
Node.js MongoDB Ubuntu 16.04

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@127.0.0.1:27017?authSource=admin”, {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.

1 Answer

Have you started Mongo Server?

Can you connect it through command line like?

mongo -u username -p password --authenticationDatabase admin
Have another answer? Share your knowledge.