3

I am building a R script in which I need to connect to MongoDB through authentication and process the data fetched from database using rmongodb package.For that I have created a new MongoDB user in version 3.0.4 and while connecting to mongoDB from R script authentication fails. Also the user is authenticated successfully through mongo shell. Also authentication works fine while I authenticate user created in MongoDB version 2.x.

Following is code snippet which we have used in R script to connect to Mongo database.

mongo <- mongo.create("127.0.0.1", "", "user", "pass", "db", 0L )

While executing above code snippet we receive the following response

error: Loading required package: rmongodb Authentication failed.

Please suggest me appropriate solution to authentication failure issue in rmongodb package.

Rubin Porwal
  • 3,218
  • 1
  • 17
  • 25

2 Answers2

4

rmongodb (as at 1.8.0) uses a legacy MongoDB C driver which doesn't have full support for MongoDB 3.0 yet. In particular, it will not support using the new SCRAM-SHA-1 default authentication or optional WiredTiger storage engine.

There's an rmongodb issue in Github tracking this: Compatibility with version 3.0 of MongoDB.

Until rmongodb is updated your options (in order of least to most hasslesome) include:

  • use a different driver which does have MongoDB 3.x support (i.e. RMongo 0.1.0 or newer)

  • use MongoDB 2.6

  • use MongoDB 3.x but downgrade to the older MONGO-CR auth (and do not use WiredTiger or any alternative storage engines)

Stennie
  • 57,971
  • 14
  • 135
  • 165
  • NB: It doesn't look like RMongo 0.1.0 has landed on CRAN yet, so you may have to build the package from the master branch on github. – Stennie Jun 26 '15 at 08:24
  • I have configured MongoDB 3 to support MONGODB-CR authentication and as a result of it user is successfully authenticated and also R script is able to access collections with wiredTiger storage engine – Rubin Porwal Jun 29 '15 at 04:56
  • 1
    @RubinPorwal Great to hear you had success! Aside from authentication, the main issue using an older driver with MongoDB 3.0 is the inability to list collections or indexes if your server is using non-default storage engines like WiredTiger. There's are new [`listCollections`](http://docs.mongodb.org/manual/reference/command/listCollections/) and [`listIndexes`](http://docs.mongodb.org/manual/reference/command/listIndexes/) server commands that the drivers need to implement. – Stennie Jun 29 '15 at 12:24
3

Having just gone through this myself, I thought I'd add my two cents in case it helps someone.

@Stennie is right on target to with the authentication stuff. So if you want to use mongo 3 the way to get it going is as follows (this is from a ubuntu install).

1) sudo nano /etc/mongod.conf 2) Comment out the "auth=TRUE" line 3) sudo service mongod restart 4) login to mongo shell (now with no authentication so everything is open) 5) use admin 6) Execute the following: var schema = db.system.version.findOne({"_id" : "authSchema"}) schema.currentVersion = 3 db.system.version.save(schema) (the above 3 commands are from here: https://jira.mongodb.org/browse/SERVER-17459) 7) create your users in the appropriate database 8) to make sure the right credentials are set up, type db.system.users.find() and amke sure they have the MONGODB-CR credentials 9) quit mongo 10) ucomment out the authentication line in /etc/mongod.conf 11) restart mongodb using sudo service mongod restart

should work now! I hope that helps someone...

user1357015
  • 9,314
  • 16
  • 56
  • 100