Unauthorized not authorized on exampledb to execute command on mongo

After a recent update to mongo 2.6.8 on centos 6.6  I started getting errors saying not authorized to execute command.  My problem turned out to be that the hostnames in my cluster (rs.status()) differed from the hostnames that the clients used to connect.  The solution was to make the clients use the same hostnames used in the cluster. (Alternatively I assume you could have the hostnames used in the cluster, but this is pretty painful).

rs.status():

rs0:PRIMARY> rs.status()

{...,"members" : [
{"name" : "host1-i.example.com:27017",...},
{"name" : "host2-i.example.com:27017",...},
{"name" : "host3-i.example.com:27017",}
],"ok" : 1}
and I was connecting with host1.example.com,host2.example.com,host3.example.com

I changed to use host1-i.example.com,host2-i.example.com,host3-i.example.com

(by adding entries to /etc/hosts). And problem solved.

 

log4j.log file:

Caused by: com.mongodb.CommandFailureException: { "serverUsed" : "server1.example.com:27017" , "ok" : 0.0 ,
 "errmsg" : "not authorized on exampledb to execute command { insert: \"example_json\", ordered: true,
 documents: [ { _id: ObjectId('54f315f3ed50dea004774c39'), key: \"b3tUPw\", json: { test: 1 } } ] }" , "code" : 13}

and in mongod.log:

2015-03-01T07:36:23.751-0600 [conn2933] Unauthorized not authorized on exampledb to execute command { update: "example_json", ordered: true, updates: [ { q: { key: "n6ymtS" }, u: { key: "n6ymtS", json: { id: "n6ymtl", params: {} } } ] }

Mongo server version:   mongodb-org-server-2.6.8-1.x86_64

 

Leave a Reply