Functions for querying, creating, updating and deleting user documents.
Functions in this module follow the node.js callback style. The first argument is an error object (if one occurred), the following arguments are the results of the operation. The callback is always the last argument to a function.
Deletes an existing user document, given its username. You must be logged in as an administrative user for this function to succeed.
- username - String - The username of the user to delete
- callback(err,response) - Function - Function called on completion of the operation
users.delete('username', function (err) {
if (err) // there was an error deleting the user
else // success
});Get a single user by username. The third argument to the callback is an info object which returns the authdb used, and the real id of the user with "org.couchdb.user:" prefix.
- username - String - The username of the user to get
- callback(err,user,info) - Function - Function called on completion
users.get('testuser', function (err, doc) {
if (err) // there was an error fetching the user document
else // success
});List users in the auth database. By default, it will list all users.
By using the optional q parameter, you can pass additional options to the
_al_docs` view for the auth database.
- q - Object - Query parameters (optional)
- callback(err,list) - Function - Function called with the resulting list (or error)
users.list(function (err, list) {
if (err) // there was an error querying the auth database
else // success
});Creates a new user document with given username and password. If properties.roles contains _admin', user will be made admin.
- username - String - The username of the new user
- password - String - The unhashed password for the new user
- properties - Object - Additional properties such as roles to extend the user document with (optional)
- callback(err,response) - Function - Function called on completion or error
users.create('testuser', 'testing', {roles: ['example']}, function (err) {
if (err) // an error occurred
else // successfully created new user
});Updates an existing user document. Similar usage to the create function.
- username - String - The username of the new user
- password - String - The unhashed password for the new user
- properties - Object - Additional properties such as roles to extend the user document with (optional)
- callback(err,response) - Function - Function called on completion or error
users.update('testuser', 'testing', {roles: ['example']}, function (err) {
if (err) // an error occurred
else // successfully updated user
});