not able to connect to mongodb hosted on remote server using monk
Asked Answered
P

1

2

I am using node js, and for the backend i am using mongodb

For connecting to DB, if i use the below line, it is fetching data

var db = monk('localhost:27017/nodetest2');

But if i change that to below line, its not fetching the data

var db = monk('mongodb://username:[email protected]:27483/userdb');

I have created the collection with same name in both places

router.get('/userlist', function (req, res) {
    var db = req.db;
    var collection = db.get('userlist');
    collection.find({}, {}, function (e, docs) {
        res.json(docs);
    });
});
Pavla answered 28/7, 2015 at 5:50 Comment(5)
You should start by adding error handling. I can connect to that database just fine (but I can't perform queries because I don't have the correct username/password, so queries return an authentication error).Trenttrento
thanks @Trenttrento will do that are there any config/settings level changes that i have to do to enable this?Pavla
You should first find out why the queries aren't working; using a standalone script for that is easiest; if you get any errors (the e variable in the query callback), log them so you get an idea what's going on (perhaps username/password mismatch).Trenttrento
This is likely permissions and nothing to do with monk. Try connections from the shell and where that does not work, go back to your mongolab account and change permissions until you have something working.Fultz
Thanks robertklep, blakes Seven Its permission issue, i tried with different user id and password and it workedPavla
S
0
  1. Check if your IP is whitelisted.
  2. try to connect via shell

Add an error handling.

const db = require("monk")(uri);
db.then(() => {
  console.log('Connected correctly to server')
})
Stork answered 28/9, 2020 at 2:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.