0

I am building a practice project and trying to connect to the MongoDB on the remote server host by Modulus. I try to connect with the following code with correct username and password but still cannot log into the database. Would you please provide some advice.

The following is my connection code - /**** Connect to MongoDB ****/

MongoClient mongo = new MongoClient("jello.modulusmongo.net", 27017);
DB db = mongo.getDB("b9ybeDiw");
boolean auth = db.authenticate("root", "password".toCharArray());

if (auth) {
    System.out.println("Login Successful!");
} else {
    System.out.println("login Failed");

The following is the error message-

com.mongodb.MongoException: not authorized for insert on b9ybeDiw.user
at com.mongodb.CommandResult.getException(CommandResult.java:100)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:134)
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:142)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:183)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:155)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:270)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:226)
at com.mongodb.DBCollection.insert(DBCollection.java:75)
at com.mongodb.DBCollection.insert(DBCollection.java:59)
at com.mongodb.DBCollection.insert(DBCollection.java:104)
at yuyang.mongo.App.main(App.java:52)
Community
  • 1
  • 1
Randal
  • 13
  • 5
  • Your exception says "not authorized for insert" - are you sure you have the right login and password? – Krease Jul 12 '16 at 05:01
  • Hi Krease, I am sure I have the correct username and password. I try to build the connection like this, and try to insert something afterward. But it does not work. – Randal Jul 12 '16 at 05:04
  • 1
    it may help http://stackoverflow.com/questions/20525103/what-mongodb-user-privileges-do-i-need-to-add-a-user-to-a-new-another-mongo-data – Sitansu Jul 12 '16 at 05:17
  • http://www.tutorialspoint.com/mongodb/mongodb_java.htm – Sitansu Jul 12 '16 at 05:27
  • Hi Sitansu, Thank you for sharing the introduction, I am reading the tutorial and trying to fix it. – Randal Jul 12 '16 at 05:37

0 Answers0