Package Exports
- mongodb-atlas-api-client
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mongodb-atlas-api-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Mongodb atlas api client for NODEJS
A mongdb atlas api client for nodejs.
How to install
npm install mongodb-atlas-api-clientGetting Started
The basic syntax is:
Atlas API uses HTTP Digest Authentication. It essentially requires a username and a password which are hashed using a unique server-generated value called a nonce. The username is the API public key and the password is the corresponding private key.
const getClient = require("mongodb-atlas-api-client");
const {user, cluster} = getClient({
"publicKey": "some public key",
"privateKey": "some private key",
"baseUrl": "https://cloud.mongodb.com/api/atlas/v1.0",
"projectId": "some project/group id"
});
const options = {
"envelope": true,
"itemsPerPage": 10,
"pretty": true
}
const response = await user.getAll(options); // get All users
const response = await cluster.get("someClusterName"); // get single cluster
const response = await user.delete("someUserName", options); // delete single user
const response = await user.create(body, options); // create user
const response = await user.update("someUserName", body, options); // update user
Running the tests
npm test
API
Following entities are currently supported
User
user.get(username, [options]) ⇒ Promise
Function - Returns the details of user name passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| username | String |
name of the user for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/database-users-get-single-user/
user.getAll([options]) ⇒ Promise
Function - Returns all the users. Pagination can be controlled via options object.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/database-users-get-all-users/
user.create(body, [options]) ⇒ Promise
Function - Creates the user as per body passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| body | Object |
Body which has details for user which needs to be created | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/database-users-create-a-user/
user.update(username, body, [options]) ⇒ Promise
Function - Updates the user for the username passed. It only updates the properties passed in body.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| username | String |
name of the user for which details needs to be updated | |
| body | Object |
Body which has details for user which needs to be updated | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/database-users-update-a-user/
user.delete(username, [options]) ⇒ Promise
Function - Deletes the user name passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| username | String |
name of the user which needs to be deleted | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/database-users-delete-a-user/
Cluster
cluster.get(clustername, [options]) ⇒ Promise
Function - Returns the details of cluster name passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| clustername | String |
name of the cluster for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/clusters-get-one/
cluster.getAll([options]) ⇒ Promise
Function - Returns all the clusters. Pagination can be controlled via options object.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/clusters-get-all/
cluster.getAdvanceConfiguration(clustername, [options]) ⇒ Promise
Function - Returns the advance configuration of cluster name passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| clustername | String |
name of the cluster for which advance configuration needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/clusters-get-advanced-configuration-options/
cluster.create(body, [options]) ⇒ Promise
Function - Creates the cluster as per body passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| body | Object |
Body which has details for cluster which needs to be created | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/clusters-create-one/
cluster.update(clustername, body, [options]) ⇒ Promise
Function - Updates the cluster for the clustername passed. It only updates the properties passed in body.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| clustername | String |
name of the cluster for which details needs to be updated | |
| body | Object |
Body which has details for cluster which needs to be updated | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/clusters-modify-one/
cluster.updateAdvanceConfiguration(clustername, body, [options]) ⇒ Promise
Function - Updates the advance configuration of cluster for the clustername passed. It only updates the properties passed in body.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| clustername | String |
name of the cluster for which advance configuration needs to be updated | |
| body | Object |
Body which has details for cluster which needs to be updated | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/clusters-modify-advanced-configuration-options/
cluster.testPrimaryFailOver(clustername, [options]) ⇒ Promise
Function - Tests failure of primary replica set member.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| clustername | String |
name of the cluster for which failure needs to be tested | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/clusters-test-failover/
cluster.delete(clustername, [options]) ⇒ Promise
Function - Deletes the cluster name passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| clustername | String |
name of the cluster which needs to be deleted | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/clusters-delete-one/
CustomDbRole
customDbRole.get(rolename, [options]) ⇒ Promise
Function - Returns the details of role name passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| rolename | String |
name of the role for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/custom-roles-get-single-role/
customDbRole.getAll([options]) ⇒ Promise
Function - Returns all the roles. Pagination can be controlled via options object.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/custom-roles-get-all-roles/
customDbRole.create(body, [options]) ⇒ Promise
Function - Creates the role as per body passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| body | Object |
Body which has details for role which needs to be created | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/custom-roles-create-a-role/
customDbRole.update(rolename, body, [options]) ⇒ Promise
Function - Updates the role for the rolename passed. It only updates the properties passed in body.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| rolename | String |
name of the role for which details needs to be updated | |
| body | Object |
Body which has details for role which needs to be updated | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/custom-roles-update-a-role/
customDbRole.delete(rolename, [options]) ⇒ Promise
Function - Deletes the role name passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| rolename | String |
name of the role which needs to be deleted | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/custom-roles-delete-a-role/
ProjectWhitelist
projectWhitelist.get(whitelistentry, [options]) ⇒ Promise
Function - Returns the details of whitelistentry name passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| whitelistentry | String |
name of the whitelistentry for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/whitelist-get-one-entry/
projectWhitelist.getAll([options]) ⇒ Promise
Function - Returns all the whitelistentries. Pagination can be controlled via options object.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/whitelist-get-all/
projectWhitelist.create(body, [options]) ⇒ Promise
Function - Creates the whitelistentry as per body passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| body | Object |
Body which has details for whitelistentry which needs to be created | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/whitelist-add-one/
projectWhitelist.update(body, [options]) ⇒ Promise
Function - Updates the whitelistentry passed. It only updates the properties passed in body.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| body | Object |
Body which has details for whitelistentry which needs to be updated | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/whitelist-update-one/
projectWhitelist.delete(whitelistentry, [options]) ⇒ Promise
Function - Deletes the whitelistentry name passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| whitelistentry | String |
name of the whitelistentry which needs to be deleted | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/whitelist-delete-one/
Project
project.getById(projectId, [options]) ⇒ Promise
Function - Returns the details of project id passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| projectId | String |
project id for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/project-get-one/
project.getByName(projectName, [options]) ⇒ Promise
Function - Returns the details of project name passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| projectId | String |
project name for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/project-get-one-by-name/
project.getTeamsByProjectId(projectId, [options]) ⇒ Promise
Function - Returns the teams of project id passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| projectId | String |
project id for which teams needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/project-get-teams/
project.getAll([options]) ⇒ Promise
Function - Returns all the projects. Pagination can be controlled via options object.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/project-get-all/
project.create(body, [options]) ⇒ Promise
Function - Creates the project as per body passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| body | Object |
Body which has details for project which needs to be created | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/project-create-one/
project.assignTeams(projectId, body, [options]) ⇒ Promise
Function - Assigns the teams for the projectId passed. It only updates the properties passed in body.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| projectId | String |
Id of the project for which teams needs to be associated | |
| body | Object |
Body which has details for teams which needs to be associated | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/project-add-team/
project.delete(projectId, [options]) ⇒ Promise
Function - Deletes the project id passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| projectId | String |
Id of the project which needs to be deleted | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/project-delete-one/
project.removeUserFromProject(projectId, userId, [options]) ⇒ Promise
Function - Removes the user id passed from the project.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| userId | String |
Id of the user which needs to be removed from project | |
| projectId | String |
Id of the project | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/project-remove-user/
Organization
organization.getById(organizationId, [options]) ⇒ Promise
Function - Returns the details of organization id passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| organizationId | String |
org§ id for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/organization-get-one/
organization.getAllUsersForOrganization(organizationId, [options]) ⇒ Promise
Function - Returns all the users for organization id passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| organizationId | String |
organization id for which users needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/organization-users-get-all-users/
organization.getAllProjectsForOrganization(organizationId, [options]) ⇒ Promise
Function - Returns all the projects for organization id passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| organizationId | String |
organization id for which projects needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/organization-get-all-projects/
organization.getAll([options]) ⇒ Promise
Function - Returns all the organizations. Pagination can be controlled via options object.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/organization-get-all/
organization.rename(organizationId, body, [options]) ⇒ Promise
Function - Renames the organization
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| organizationId | String |
Id of the organization for which needs to be renamed | |
| body | Object |
Body which has details for organization which needs to be renamed | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/organization-rename/
organization.delete(organizationId, [options]) ⇒ Promise
Function - Deletes the project id passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| organizationId | String |
Id of the organization which needs to be deleted | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/organization-delete-one/
AtlasUser
atlasUser.getById(userId, [options]) ⇒ Promise
Function - Returns the details of user id passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| userId | String |
Id of the user for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/user-get-by-id/
atlasUser.getByName(username, [options]) ⇒ Promise
Function - Returns the details of user name passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| username | String |
Name of the user for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/user-get-one-by-name/
atlasUser.getAll([options]) ⇒ Promise
Function - Returns all the users. Pagination can be controlled via options object.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/user-get-all/
atlasUser.create(body, [options]) ⇒ Promise
Function - Creates the atlas user as per body passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| body | Object |
Body which has details for atlas user which needs to be created | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/user-create/
atlasUser.update(userId, body, [options]) ⇒ Promise
Function - Updates the user for the userId passed. It only updates the properties passed in body.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| userId | String |
Id of the user for which details needs to be updated | |
| body | Object |
Body which has details for user which needs to be updated | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/user-update/
Event
event.get(eventId, [options]) ⇒ Promise
Function - Returns the details of event id passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| eventId | String |
id of the event for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/events-projects-get-one/
event.getAll([options]) ⇒ Promise
Function - Returns all the events. Pagination can be controlled via options object.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/events-projects-get-all/
event.getByOrganizationId(organizationId, eventId, [options]) ⇒ Promise
Function - Returns the details of event id passed for organization id.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| organizationId | String |
id of the organization for which details needs to be retrieved | |
| eventId | String |
id of the event for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/events-orgs-get-one/
event.getAllByOrganizationId(organizationId, [options]) ⇒ Promise
Function - Returns all the events. Pagination can be controlled via options object.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| organizationId | String |
id of the organization for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/events-orgs-get-all/
Alert
alert.get(alertId, [options]) ⇒ Promise
Function - Returns the details of alert id passed.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| alertId | String |
id of the alert for which details needs to be retrieved | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/alerts-get-alert/
alert.getAll([options]) ⇒ Promise
Function - Returns all the alerts. Pagination can be controlled via options object.
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/alerts-get-all-alerts/
event.acknowledge(alertId, [options]) ⇒ Promise
Function - Acknowledge or unacknowledge an alert
Returns: Promise - - promise which resolves on success and rejects on error
| Param | Type | Default | Description |
|---|---|---|---|
| alertId | String |
id of the alert which needs to be acknowledged | |
| body | Object |
Body which has details for alert which needs to be acknowledged | |
| [options] | Object |
{} |
Optional object containing extra query strings which will be passed to atlas api |
More details - https://docs.atlas.mongodb.com/reference/api/alerts-acknowledge-alert/
