Navigation

Restore Archived Data

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 restore archived data archived to your Atlas cluster. You must use the $match and $out pipeline stages to get the archived data into a temporary collection and use the $merge to move the data back into the original collection.

This page describes how to restore using $match, $out, and $merge pipeline stages.

Procedure

1

Pause the online archive associated with the collection whose archived data you wish to restore.

See Pause and Resume Archiving for more information.

2

Connect to your Atlas cluster and online archive using the connection string.

See Connect to Online Archive and Cluster for more information.

3

Use $match and $out to Atlas to migrate data from the archive to a temporary collection on the Atlas cluster.

Use $match to identify the documents that match the criteria for restoring and use $out to Atlas to write the documents to a temporary collection on the Atlas cluster. For example:

db.<collection>.aggregate([
  { $match: { $expr: { <aggregation expression> } } },
  { $out: {
    "atlas": {
      "projectId": "<atlas-project-ID>",
      "clusterName": "<atlas-cluster-name>",
      "db": "<atlas-database-name>",
      "coll": "<atlas-collection-name"
    }
  } }
])
4

Use $merge to move the data from the temporary collection to the original collection.

  1. Close the connection you opened in step 2 to your Atlas cluster and online archive.

  2. Connect to your Atlas cluster using the connection string.

  3. Use $merge to move the data from the temporary collection to the original collection. For example:

    db.<collection>.aggregate([
      {
        $merge: {
          into: "<collection>",
          on: <identifier field>,
          whenMatched: "<replace|merge>",
          whenNotMatched: "<insert|discard|fail>"
        }
      }
    ])
    
5

Verify data in the Atlas cluster and delete the online archive.

See Delete an Online Archive for more information.