Mongolab Authentication Failed Java

Sushank Dahiwadkar

I am trying to connect to MongoLab Database with Java client. But not able to authenticate with Mongolab server with following code:

Mongo mongo = new Mongo("ds03456.mongolab.com", 51575);
DB db = mongo.getDB("sample");
boolean auth = db.authenticate("test", "test".toCharArray());

And i tried with same credentials with Node.js and it works fine:

var server = new Server('ds03456.mongolab.com', 51575);
var db = new Db('sample', server);
db.open({
      client.authenticate('test', 'test', function(err, success){
        //success = true.
      })
});

what could be the possible error?

Ali Dehghani

Mongolab is using MongoDB 3.0+ and you're using version 2.0 deprecated classes to authenticate. This should work:

MongoClientURI clientURI = new MongoClientURI("mongodb://user:pass@address:port/dbname");
MongoClient client = new MongoClient(clientURI);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Remote MongoLab MongoDB login failed error

From Dev

Auth failed, code 18 when connecting to MongoLab database

From Dev

Java Springboot application returning password authentication failed for user "postgres"

From Dev

Java MongoDB Client: authentication failed when access to a server not configured to use an authentication

From Dev

Java MongoDB Client: authentication failed when access to a server not configured to use an authentication

From Dev

FEDEX API, Authentication Failed

From Dev

Public Key authentication failed

From Dev

Authentication failed for user: null

From Dev

Authentication failed on the git remote

From Dev

Authentication failed for Azure Git

From Dev

MongoDB 3.2 authentication failed

From Dev

Django authentication : CSRF Failed

From Dev

Failed NetSuite RESTlet authentication

From Dev

"Authentication failed" in Wayland application

From Dev

Authentication failed for user: null

From Dev

Mongoose throwing `Authentication failed`

From Dev

postgres ident authentication failed

From Dev

SmartGit Hg "Authentication Failed"

From Dev

Public Key authentication failed

From Dev

MongoDB authentication failed?

From Dev

useradd PAM authentication failed

From Dev

SSH authentication failed

From Dev

Failed NetSuite RESTlet authentication

From Dev

Shiro Authentication failed

From Dev

MongoError: Authentication failed

From Dev

PayPal Client Authentication Failed

From Dev

LightDM: "Failed during authentication"

From Dev

ssh Authentication failed on Mac

From Dev

Auth Failed trying to connect from a Fantom script to a MongoDB hosted in MongoLab. What's wrong?