因为某种奇怪的原因,我的用户没有被授权在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中手动分配用户管理员角色是否需要特定的方法。
mongo ds037395.mongolab.com:37395
。 - Alex