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)