设置mongodb时,我已创建管理员帐号:
use admin
db.createUser(
{
user: "demo",
pwd: "demo",
roles:
[
{
role: "userAdminAnyDatabase",
db: "admin"
}
]
}
)
但是当使用java连接数据库时:
MongoClient mongoClient = new MongoClient("localhost", 27017);
DB db = mongoClient.getDB("mydb");
String username = "demo";
String password = "demo";
boolean auth = db.authenticate(username, password.toCharArray());
System.out.println(auth);
结果错误,有人可以帮助我???