Using terminal, I can add user using db.createUser(user, writeConcern)
and remove it using db.dropUser(username, writeConcern)
How to add and remove users in MongoDB Java Driver 2.13?
Using terminal, I can add user using db.createUser(user, writeConcern)
and remove it using db.dropUser(username, writeConcern)
How to add and remove users in MongoDB Java Driver 2.13?
In MongoDB Java Driver 2.13 its very similar to to the shell. To add a user you can use DB.addUser
and to remove a user you can use DB.removeUser
- see the api documentation for the arguments
It should be noted that these methods are deprecated and will be removed in the future most likely in the 4.0 release.
The preferred method is to use the commands directly. So you can use DB.command
- the syntax for the commands can be found in the general MongoDB documentation, see createUser and see dropUser.
Removes the user from the current database.
> db.dropUser(username, writeConcern)
username - The name of the user to remove from the database.
writecConcern - Optional. The level of write concern for the removal operation. The writeConcern document takes the same fields as the getLastError command.
Example:
use products
db.dropUser("reportUser1", {w: "majority", wtimeout: 5000})