/** * Adds or updates a user for this database * * <p>Never create or modify users over an insecure network without the use of TLS.</p> * @param userName the user name * @param password the password * @return the result of executing this operation * @throws MongoException if the operation failed * @mongodb.driver.manual administration/security-access-control/ Access Control * @mongodb.driver.manual reference/command/createUser createUser * @mongodb.driver.manual reference/command/updateUser updateUser * @deprecated Use {@code DB.command} to call either the createUser or updateUser command */ @Deprecated public WriteResult addUser(final String userName, final char[] password) { return addUser(userName, password, false); }
/** * Adds or updates a user for this database * * <p>Never create or modify users over an insecure network without the use of TLS.</p> * @param userName the user name * @param password the password * @return the result of executing this operation * @throws MongoException if the operation failed * @mongodb.driver.manual administration/security-access-control/ Access Control * @mongodb.driver.manual reference/command/createUser createUser * @mongodb.driver.manual reference/command/updateUser updateUser * @deprecated Use {@code DB.command} to call either the createUser or updateUser command */ @Deprecated public WriteResult addUser(final String userName, final char[] password) { return addUser(userName, password, false); }
MongoClient mongoClient = new MongoClient("127.0.34.1", 89); DB db = mongoClient.getDB("test"); try { db.addUser("user", new char[] {'p', 'a', 's', 's'}); } catch(Exception e) { MongoTimeoutException exception}
public User(String name) { DB db = new DB(); db.addUser(name); }