RejectedSoftware Forums

Sign up

Mongodb remote database authentication problem

    MongoClientSettings cfg;

    cfg = MongoClientSettings.init;
    parseMongoDBUrl(cfg, "mongodb://dbuser:dbpassword@ds157964.mlab.com:57964/kullanicilar2");
    import std.stdio;

    writeln(cfg.database);
    writeln(cfg.username);
    writeln(cfg.hosts[0].name);
    writeln(cfg.hosts[0].port);
    //writeln(cfg.password);
    
    
    auto client = connectMongoDB("mongodb://dbuser:dbpassword@ds157964.mlab.com:57964/kullanicilar2");

When I try to connect a remote mongodb I get authentication errors.

vibe.db.mongo.connection.MongoAuthException@../../.dub/packages/vibe-d-0.8.1/vibe-d/mongodb/vibe/db/mongo/connection.d(527): Authentication failed.

../../.dub/packages/vibe-d-0.8.1/vibe-d/mongodb/vibe/db/mongo/connection.d:527 D4vibe2db5mongo10connection15MongoConnection12authenticateMFNfZ38T9lambda4TmTS4vibe4data4bson4BsonZ9lambda4MFNfmKS4vibe4data4bson4BsonZv [0x876b36]<br>../../.dub/packages/vibe-d-0.8.1/vibe-d/mongodb/vibe/db/mongo/connection.d:406 @safe int vibe.db.mongo.connection.MongoConnection.recvReply!(vibe.data.bson.Bson).recvReply(int, scope @safe void delegate(long, vibe.db.mongo.flags.ReplyFlags, int, int), scope @safe void delegate(ulong, ref vibe.data.bson.Bson)) [0x878b01]<br>../../.dub/packages/vibe-d-0.8.1/vibe-d/mongodb/vibe/db/mongo/connection.d:253 @safe void vibe.db.mongo.connection.MongoConnection.query!(vibe.data.bson.Bson).query(immutable(char)[], vibe.db.mongo.flags.QueryFlags, int, int, vibe.data.bson.Bson, vibe.data.bson.Bson, scope @safe void delegate(long, vibe.db.mongo.flags.ReplyFlags, int, int), scope @safe void delegate(ulong, ref vibe.data.bson.Bson)) [0x878865]<br>../../.dub/packages/vibe-d-0.8.1/vibe-d/mongodb/vibe/db/mongo/connection.d:525 @safe void vibe.db.mongo.connection.MongoConnection.authenticate() [0x8767b7]<br>../../.dub/packages/vibe-d-0.8.1/vibe-d/mongodb/vibe/db/mongo/connection.d:187 @safe void vibe.db.mongo.connection.MongoConnection.connect() [0x874609]<br>../../.dub/packages/vibe-d-0.8.1/vibe-d/mongodb/vibe/db/mongo/client.d:63 D4vibe2db5mongo6client11MongoClient6ctorMFNfAyaZ9lambda2MFNfZC4vibe2db5mongo10connection15MongoConnection [0x87133b]
../../.dub/packages/vibe-d-0.8.1/vibe-d/core/vibe/core/connectionpool.d:94 @safe vibe.core.connectionpool.LockedConnection!(vibe.db.mongo.connection.MongoConnection).LockedConnection vibe.core.connectionpool.ConnectionPool!(vibe.db.mongo.connection.MongoConnection).ConnectionPool.lockConnection() [0x871a7e]
../../.dub/packages/vibe-d-0.8.1/vibe-d/mongodb/vibe/db/mongo/client.d:152 @safe vibe.core.connectionpool.LockedConnection!(vibe.db.mongo.connection.MongoConnection).LockedConnection vibe.db.mongo.client.MongoClient.lockConnection() [0x8715d2]
../../.dub/packages/vibe-d-0.8.1/vibe-d/mongodb/vibe/db/mongo/client.d:62 @safe vibe.db.mongo.client.MongoClient vibe.db.mongo.client.MongoClient._ctor(immutable(char)[]) [0x8712b9]<br>../../.dub/packages/vibe-d-0.8.1/vibe-d/mongodb/vibe/db/mongo/mongo.d:87 @safe vibe.db.mongo.client.MongoClient vibe.db.mongo.mongo.connectMongoDB(immutable(char)[]) [0x88399a]<br>source/app.d:62 Dmain [0x844ff9]
Program exited with code 1

On the other side I may connect to the remoto database from mongo shell using same credentials.

Re: Mongodb remote database authentication problem

On Sat, 30 Sep 2017 06:33:01 GMT, Erdem wrote:

(...)

When I try to connect a remote mongodb I get authentication errors.

vibe.db.mongo.connection.MongoAuthException@../../.dub/packages/vibe-d-0.8.1/vibe-d/mongodb/vibe/db/mongo/connection.d(527): Authentication failed.
(...)

On the other side I may connect to the remoto database from mongo shell using same credentials.

It could be that an unsupported or disabled authentication mechanism is used (currently it still defaults to MONGODB-CR, which is not accepted by default for recent versions). Does adding &authmechanism=SCRAM-SHA-1 to the URL help?

Re: Mongodb remote database authentication problem

No but I might connect the same database using Pymongo.