If your Java application uses Spring Data for accessing to MongoDB and it throws error messages like this: "... Not authorized for query ..." or this: "... errmsg" : "unauthorized... ",

then check your application context xml-file:

<mongo:db-factory dbname="${mongo.database}" host="${mongo.host}" id="mongoDbFactory" port="${mongo.port}" username="${mongo.username}" password="${mongo.password}"/>

I used Spring Roo for source code generating and attributes username and password weren`t generated per default.