I have deployed the MongoDb using the Google cloud Launcher and BITNAMI. I got the username and password from the deployment console.
I used the keys.json for the credentials in nodejs application -
{
"mongoHost": "104.198.142.198",
"mongoPort": "27017",
"mongoDatabase": "transM",
"mongoUser": "root",
"mongoPass": "secret"
}
My App.js -
const username = nconf.get('mongoUser');
const pass = nconf.get('mongoPass');
const host = nconf.get('mongoHost');
const port = nconf.get('mongoPort');
let uri = `mongodb://${username}:${pass}@${host}:${port}`;
if (nconf.get('mongoDatabase')) {
uri = `${uri}/${nconf.get('mongoDatabase')}`;
}
console.log(uri);
mongoose.connect(uri);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
// we're connected!
console.log("Connected correctly Database to server");
});
The stderr log shows Authentication fails. But when I try remote connection using the same in terminal -
mongo admin --username root -p --host 104.198.142.198 --port 27017
it lets me log in.
Please note -
In the example by google the mlabs hostname is used -
https://cloud.google.com/nodejs/resources/databases/mongodb
{
"mongoHost": "ds053894.mlab.com",
"mongoPort": "53894",
"mongoDatabase": "mydata",
"mongoUser": "myapp",
"mongoPass": "mypword",
}
{
"mongoHost": "ds053894.mlab.com",
"mongoPort": "53894",
"mongoDatabase": "mydata",
"mongoUser": "myapp",
"mongoPass": "mypword",
}
Can you please help to get the correct host name for BITNAMI Mongo instance.