我正在构建一个练习项目并尝试通过Modulus连接到远程服务器主机上的MongoDB。我尝试使用正确的用户名和密码连接以下代码,但仍无法登录数据库。请你提供一些建议。
以下是我的连接代码 - / ****连接到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");
以下是错误消息 -
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)