One of Those "not authorized for query on db.collection" Errors (On Heroku)

1,977 views
Skip to first unread message

Neil Chaudhuri

unread,
Jul 30, 2015, 7:06:20 PM7/30/15
to ReactiveMongo - http://reactivemongo.org
I have deployed a Play 2.3 application with the RM plugin to Heroku. The database connection is defined in application.conf like this:

mongodb.uri=${MONGODB_URI}

where MONGODB_URI is a config var defined in Heroku to map to the URL provided by the Mongo add-on.

When I deploy my application, I see this when I try to load a page:

ReactiveMongoPlugin starting... 
ReactiveMongoPlugin successfully started with db ‘myDB’! Servers: 
[server1:port] 
[server2:port] 
Application started (Prod) 
State changed from starting to up 
(then when first page loaded)
DatabaseException['not authorized for query on collection’ (code = 13)] 

This happens for every page that is first loaded on deploy. After that, things seem to work though on occasion I've seen the same error thereafter.

Can you tell me what might be causing this? Could this be a matter of the plugin configuration or the Mongo instance configuration on Heroku?

Thanks.

Neil Chaudhuri

unread,
Jul 30, 2015, 7:11:42 PM7/30/15
to ReactiveMongo - http://reactivemongo.org, ne...@vidyasource.com
Forgot to mention my RM version is 0.11.4.play23.

Cédric Chantepie

unread,
Jul 31, 2015, 7:43:25 AM7/31/15
to ReactiveMongo - http://reactivemongo.org, ne...@vidyasource.com
There are several issues with using MongoDB from Heroku (probably related to its app un/reloading app mechanism).

Do you use the MongoLab addon?

The sample app configured without this Heroku addon but directly with MongoLab host is working with no issue.

Neil Chaudhuri

unread,
Jul 31, 2015, 8:47:44 AM7/31/15
to ReactiveMongo - http://reactivemongo.org, ne...@vidyasource.com, chantep...@gmail.com
I am actually using the Compose add-on, and I agree it is probably a loading problem. Just thought I would ask for some different eyes on the issue.

The app I am using is one of the free dynos that sleeps. I'll be checking to see if the issue persists when I start paying for one that doesn't.

Thanks.

Zoro

unread,
Sep 26, 2015, 10:46:34 AM9/26/15
to ReactiveMongo - http://reactivemongo.org
I also getting this. But i run on local machine. Every first loaded page return "not authorized for query on ...".  After refresh all works fine.

Play 2.4.3
play2-reactivemongo 0.11.2.play24 

Camilo A. Navas

unread,
Sep 30, 2015, 5:57:28 PM9/30/15
to ReactiveMongo - http://reactivemongo.org
Happens to me too, locally every time I restart my server

Joseph Hui

unread,
Oct 25, 2015, 6:06:13 AM10/25/15
to ReactiveMongo - http://reactivemongo.org
I have the same problem. No matter connecting to local MongoDB or MongoLAB on Heroku, will encounter "not authorized for query on XXX' (code = 13)]" errors, and in mongodb.log, I could see 

2015-10-25T17:23:09.664+0800 D -        [conn22] User Assertion: 13:not authorized for query on XXXXX

2015-10-25T17:23:09.664+0800 I QUERY    [conn22] assertion 13 not authorized for query on XXXXX ns: XXXXX query:{}


and then shortly afterwards,


2015-10-25T17:23:09.665+0800 I ACCESS   [conn22] Successfully authenticated as principal XXXXX on posts


Reload the web app can access the data again. There code worked just fine if MongoDB ran without --auth.

Joseph Hui

unread,
Oct 25, 2015, 6:07:43 AM10/25/15
to ReactiveMongo - http://reactivemongo.org
I am using MongoDB v3.0.7 and play-reactivemong 0.11.7

Chris Linseman

unread,
Nov 16, 2015, 5:10:08 AM11/16/15
to ReactiveMongo - http://reactivemongo.org
I'm having the same issue when deploying to Heroku and connection to Mongolab.
When deployed locally everything works fine.

Olivier Droz

unread,
Nov 24, 2015, 3:17:49 AM11/24/15
to ReactiveMongo - http://reactivemongo.org
Hi All, 
This issue seems to be going on since MongoLab upgraded their free sandbox to Mongo 3 (parallel discussion on https://groups.google.com/forum/#!topic/reactivemongo/x3OZ6-hIIXk)

Works fine for me:
Application.conf:

#MongoDB

mongodb.uri = "mongodb://localhost:27017/mydb"

mongodb.uri = ${?MONGOLAB_URI}


On Heroku Config Vars add ?authMode=scram-sha1 at the end : 
mongodb://heroku_xxx:p...@node.mongolab.com:portnb/heroku_xxx?authMode=scram-sha1


Hope this helps.
Olivier
Reply all
Reply to author
Forward
0 new messages