2
votes

After running:

import 'package:mongo_dart/mongo_dart.dart';

//Create account with given credentials
createAccount(Map<String, String> credentials) async {

    Db db = new Db('mongodb://127.0.0.1/exampledb');
    await db.open();
    await db.authenticate("user", "password");

    //TODO: Post credentials into DB
}

I get an error on the Dart server saying:

Unhandled exception: Uncaught Error: {ok: 0.0, errmsg: auth failed, code: 18}

And a different error comes up up on the mongod server:

2015-09-27T20:04:25.921+0100 I ACCESS [conn1] Failed to authenticate user@exampledb with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentia ls missing in the user document

The only time when the authentication has succeeded and has allowed me access to the database is when I am using the command prompt.

Example:

$ use exampledb
$ db.auth("user", "password")

How can I make my Dart script gain access to my local mongodb, using the authenticate method?

2
Such an error normally would be thrown by mongo_dar if you are trying to authenticate with wrong credentials. I've got same error as you when I run such script on local server without sampledb databaseVadim Tsushko
After I've created user with such password in database sampledb ( in mongo shell) , same script works me without errors. By the way, your function is named createAccount and has comment abount creating account with credentials. Is it a mistake?Vadim Tsushko
I've reproduced that error with mongodb v. 3 Do you use mongodb 3?Vadim Tsushko
@VadimTsushko yes I am using MongoDB 3.0. Thank you for looking into this. I look forward to your answer.stwupton

2 Answers

3
votes

Fresh update:

Since version 0.2.5 mongo_dart supports SCRAM-SHA-1 authentification mechanism. It used by default in connections to MongoDb 3

Update:

That seems to be rather widespread problem with some drivers, programs e.t.c not supporting yet new authentication mechanism (SCRAM-SHA-1) of mongodb 3.0

By default, mongodb 3.0, do not create credentials in old format (MONGODB-CR) while creating new users.

There is round-about solution, that force mongodb 3.0 and upper version use MONGODB-CR mode while creating users. Look for example solution at https://jira.mongodb.org/browse/SERVER-17459 As stated in that thread

both new drivers and legacy software work with that solution

Obviously best solution for mongo_dart would be to add implementation of new authentication mode to the driver. Can not give any date, but I think it should be first feature that I can take in consideration as soon as I have some time for mongo_dart.

And obviously it would be great if somebody beat me at that with pull request :)

Original answer

I've reproduced that error in my environment too.

Error appears to be related to changed default authentication mode in version 3.0 of MongoDb. I'll update this answer, when the problem will be resolved

0
votes

I tried that in my mongodb 4.0.10 and mongo_dart 0.3.6 and the authentication went all right and correct just update your components if you didn't yet and everything will be fine.

PS: I know I am late but hope someone get used from my "Note".