Navigation

Create an Online Archive

Beta

Online archive is available as a Beta feature. The feature and the corresponding documentation may change at any time during the Beta stage.

You can create an online archive from the API and Atlas UI. You must have the GROUP_DATA_ACCESS_ADMIN (Project Data Access Admin) role to create an online archive.

The Atlas API uses HTTP Digest Authentication. Provide a programmatic API public key and corresponding private key as the username and password when constructing the HTTP request.

For complete documentation on configuring API access for an Atlas project, see Configure Atlas API Access.

Note

Groups and projects are synonymous terms. Your {GROUP-ID} is the same as your project ID. For existing groups, your group/project ID remains the same. The resource and corresponding endpoints use the term groups.

Base URL: https://cloud.mongodb.com/api/atlas/v1.0

Syntax

POST /groups/{GROUP-ID}/clusters/{CLUSTER-NAME}/onlineArchives

Request Parameters

Request Path Parameters

Path Element Necessity Description
GROUP-ID Required Unique identifier for the project that contains the specified cluster.
CLUSTER-NAME Required Name of the cluster that contains the collection for which you want to create an online archive.

Request Query Parameters

The following query parameters are optional:

Query Parameter Type Description Default
pretty boolean Displays response in a prettyprint format. false
envelope boolean Specifies whether or not to wrap the response in an envelope. false

Request Body Parameters

Name Type Necessity Description
collName string Required Name of the collection for which to create an online archive.
dbName string Required Name of the database that contains the collection.
criteria object Required Criteria to use for archiving data.
criteria.dateField string Required Name of an already indexed date field from the documents. Data is archived when the current date is greater than the value of the date field specified here plus the number of days specified via the expireAfterDays parameter.
criteria.expireAfterDays int Required Number of days that specifies the age limit for the data in the live Atlas cluster. Data is archived when the current date is greater than the value of the date field specified via the dateField parameter plus the number of days specified here.
partitionFields document array Optional Fields to use to partition data. You can specify up to two frequently queried fields to use for partitioning data. Note that queries that don’t contain the specified fields will require a full collection scan of all archived documents, which will take longer and increase your costs. To learn more about how partition improves query performance, see Data Structure in S3.
partitionFields.fieldName string Required Name of the field.
partitionFields.fieldType string Required Data type of the field.
partitionFields.order int Required

Position of the field in the partition. Value can be:

  • 0 - for the first position
  • 1 - for the second position
  • 2 - for the third position

By default, the date field specified in the criteria.dateField parameter is in the third position of the partition.

Response Elements

Name Type Description
id string ID of the online archive.
clusterName string Name of the cluster that contains the collection.
collName string Name of the collection.
criteria document Criteria to use for archiving data.
criteria.dateField string Name of the date field that the online archive is based on. Data is archived when the current date is greater than the value of the date field specified here plus the number of days specified via the expireAfterDays parameter.
criteria.expireAfterDays int Number of days that specifies the age limit for the data in the live Atlas cluster. Data is archived when the current date is greater than the value of the date field specified via the dateField parameter plus the number of days specified here.
dbName string Name of the database that contains the collection.
groupId string Unique identifier of the project that contains the cluster.
partitionFields document array Fields to use to partition data.
partitionFields.fieldName string Name of the field.
partitionFields.fieldType string Data type of the field.
partitionFields.order int

Position of the field in the partition. Value can be:

  • 0 - for the first position
  • 1 - for the second position
  • 2 - for the third position
paused boolean

State of the online archive. Value is:

  • true if the online archive is in paused state.
  • false if the online archive is in pending or active state.

Example

The following example request creates an online archive for an example people.employees collection in a cluster named myTestClstr. Data in the collection will be archived based on the created date field and partitioned based on the firstName and lastName fields. The criteria for archiving data specifies that data should be archived when current date is greater than the value of the created date field plus 5 days.

Example Request

curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \
--header "Content-Type: application/json" \
--include \
--request POST "https://cloud.mongodb.com/api/atlas/v1.0/groups/5e2211c17a3e5a48f5497de3/clusters/myTestClstr/onlineArchives?pretty=true" \
--data '
  {
        "dbName": "people",
        "collName": "employees",
        "partitionFields": [
              {
                      "fieldType": "string",
                      "fieldName": "firstName",
                      "order": 0
              },
              {
                      "fieldType": "string",
                      "fieldName": "lastName",
                      "order": 1
              }],
        "criteria": {
              "dateField": "created",
              "expireAfterDays": 5
  }
}'

Example Response

{
  "clusterName": "myTestClstr",
  "collName": "employees",
  "criteria": {
     "dateField": "created",
     "expireAfterDays": 5
  },
  "dbName": "people",
  "groupId": "5e2211c17a3e5a48f5497de3",
  "partitionFields": [
     {
         "fieldName": "firstName",
         "fieldType": "string",
         "order": 0
     },
     {
         "fieldName": "lastName",
         "fieldType": "string",
         "order": 1
     },
     {
         "fieldName": "created",
         "fieldType": "date",
         "order": 2
     }
  ],
  "paused": false
}

The following example request creates an online archive for an example accounting.invoices collection in a cluster named myTestClstr. Data in the collection will be archived based on the year date field. Data is partitioned based on the year field, which is moved to the first position, month field, and invoiceNumber field. The criteria for archiving data specifies that data should be archived when current date is greater than the value of the year date field plus 7 days.

Example Request

curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \
--header "Content-Type: application/json" \
--include \
--request POST "https://cloud.mongodb.com/api/atlas/v1.0/groups/5e2211c17a3e5a48f5497de3/clusters/myTestClstr/onlineArchives?pretty=true" \
--data '
  {
        "dbName": "accounting",
        "collName": "invoices",
        "partitionFields": [
              {
                      "fieldType": "date",
                      "fieldName": "createdDate",
                      "order": 0
              },
              {
                      "fieldType": "string",
                      "fieldName": "customerID",
                      "order": 1
              },
              {
                      "fieldType": "int",
                      "fieldName": "invoiceNumber",
                      "order": 2
              }],
        "criteria": {
              "dateField": "createdDate",
              "expireAfterDays": 7
  }
}'

Example Response

{
  "clusterName": "myTestClstr",
  "collName": "invoices",
  "criteria": {
     "dateField": "createdDate",
     "expireAfterDays": 7
  },
  "dbName": "accounting",
  "groupId": "5e2211c17a3e5a48f5497de3",
  "partitionFields": [
     {
         "fieldName": "createdDate",
         "fieldType": "date",
         "order": 0
     },
     {
         "fieldName": "customerID",
         "fieldType": "string",
         "order": 1
     },
     {
         "fieldName": "invoiceNumber",
         "fieldType": "int",
         "order": 2
     }
  ],
  "paused": false
}

Error Codes

If the request fails, it returns one of the following errors:

Error Code Description
INVALID_GROUP_ID The specified project ID is not valid.
CLUSTER_NOT_FOUND There is no cluster with the specified name in the specified project.
CLUSTER_DELETE_REQUESTED The cluster for the online archive is being deleted.
ONLINE_ARCHIVE_ALREADY_EXISTS An online archive with identical settings already exists.
NAMESPACE_HAS_ONLINE_ARCHIVE The collection has another active online archive and so, an online archive with the specified criteria can’t be created.
RESOURCE_NOT_FOUND The specified archive ID is not valid.