0

I have problem using play-reactivemongo to connect to MongoDB 3 and encountered the "'not authorized for query on XXX' (code = 13)" problem. The program ran perfectly ok when MongoDB was started without --auth.

The database version should be 3.0.4, as shown in the log.

2015-10-24T15:58:09.868+0800 I CONTROL  [initandlisten] db version v3.0.4

I have used version 0.11.7 play2-reactivemongo plugin.

libraryDependencies ++= Seq(
  "org.reactivemongo" %% "play2-reactivemongo" % "0.11.7.play24",

I have specified the authMode in the mongodb.uri like this.

mongodb.uri = "mongodb://postsUser:12345678@localhost:27017/posts?authMode=?authMode=scram-sha1&authSource=posts&rm.tcpNoDelay=true"

I found the following error in mongodb.log.

2015-10-24T16:41:24.977+0800 I ACCESS   [conn105] Failed to authenticate postsUser@posts with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document

Why MONGODB-CR is used instead of SCRAM-SHA-1? Suppose SCRAM-SHA-1 should be default, right?

Joseph Hui
  • 573
  • 6
  • 11
  • Okay, upgrading to MongoDB 3.0.7 solved part of the problem. There will be a "not authorized" error and then subsequent access are fine. In mongodb.log, it could be seen that a connection failed and then became good. "2015-10-25T01:08:52.286+0800 I QUERY [conn23] assertion 13 not authorized for query on posts.posts ns:posts.posts query:{} 2015-10-25T01:08:52.292+0800 I ACCESS [conn23] Successfully authenticated as principal postsUser on posts" – Joseph Hui Oct 24 '15 at 17:17
  • I think I made a typo in the mongodb.uri (authMode=?authMode=scram-sha1 ) and causing the DB to authenticate with mongodb-cr. Unfortunately, I could not try again with 3.0.4 as I had upgraded to 3.0.7 – Joseph Hui Oct 24 '15 at 17:25

2 Answers2

1

Appending following to the connection string works for me

authMode=scram-sha1

so the final connection string is

mongodb://user:pass@ipaddress:27017/litmus?3treadPreference=primary&authMode=scram-sha1

I also have nodejs script connecting to same db, interestingly it connects perfectly without appending authMode=scram-sha1 flag.

Seems to be unhandled case in reactive mongo

faisal00813
  • 400
  • 5
  • 12
0

Sorry, I made a typo in the mongodb.uri

authMode=?authMode=scram-sha1

and causing the DB to authenticate with mongodb-cr. However, I still got the "not authorized to query" error on first access to DB and subsequent db access were fine. In mongodb.log, I could see the following.

2015-10-25T01:28:45.242+0800 I QUERY    [conn33] assertion 13 not authorized for query on posts.posts ns:posts.posts query:{}
2015-10-25T01:28:45.247+0800 I ACCESS   [conn33] Successfully authenticated as principal postsUser on posts

I better start another question tomorrow.

Joseph Hui
  • 573
  • 6
  • 11