因此,由于某些奇怪的原因,我的用户无权在 krimson 数据库中写入任何内容。数据库连接成功,但授予用户写入数据库的访问权限未按预期工作。
完全错误
Caused by: com.mongodb.MongoCommandException: Command failed with error 13: 'not authorized on krimson to execute command { findandmodify: "users", query: { _id: "_id" }, fields: {}, sort: {}, new: true, upsert: true, update: { $i
nc: { _id: 1 } } }' on server ds037395.mongolab.com:37395. The full response is { "ok" : 0.0, "errmsg" : "not authorized on krimson to execute command { findandmodify: \"users\", query: { _id: \"_id\" }, fields: {}, sort: {}, new:
true, upsert: true, update: { $inc: { _id: 1 } } }", "code" : 13 }
连接代码
public static void connects(String ip, int port, String database, String username, String password) {
try {
client = new MongoClient(ip, port); /**Creating our connection between server & MongoDB*/
krimson = client.getDB(database); /**Checks if the database exists or not if not then create a new one*/
MongoCredential.createCredential(username, database, password.toCharArray()); /**Credentials used to connect to MongoDB*/
} catch (Exception e){
e.printStackTrace();
System.out.println("Linking connections failed"); /**Outputs when the database cannot connect*/
UtilServer.broadcast("&c&lThe Krimson Library did not establish a successfully connection.");
}
users = krimson.getCollection("users");
}
我尝试重新创建用户并在凭据中信誉,看看这是否是问题所在,但事实并非如此。我现在正在使用 MongoLab。所以我想知道这是否可能是问题之一或不是问题,或者是否有一种特定的方法我需要在 MongoLab 中手动分配用户管理角色