All Products
Search
Document Center

ApsaraDB for MongoDB:Key-based flashback

Last Updated:Mar 28, 2026

Key-based flashback lets you recover individual documents in a specific collection from a point in time before an accidental UPDATE or DELETE — without restoring the entire instance. Recovered data is written to a temporary collection first, so you can review it before committing the restore.

Key-based flashback has been in public preview since February 26, 2024. The feature is free of charge during public preview, and the Service-Level Agreement (SLA) is not guaranteed.

Prerequisites

Before you begin, make sure that:

  • The instance is a replica set or sharded cluster instance

  • The instance uses cloud disks for storage

  • The instance runs MongoDB 5.0 or later

  • Key-based flashback is activated on your instance — to request activation, submit a ticket

How it works

  1. Enable flashback backup on a specific collection. The configuration takes 10 minutes to take effect.

  2. After data is accidentally modified or deleted, initiate a flashback task. Specify the point in time and the document keys to restore.

  3. The system writes the recovered data to a temporary collection. Review the data there.

  4. Restore from the temporary collection to the original collection.

Limitations

Supported operations

Flashback supports restoring data from UPDATE and DELETE operations only:

  • INSERT operations cannot be rolled back.

  • Data Definition Language (DDL) operations are not tracked.

  • Documents with no recorded changes cannot be flashed back.

Keys and indexes

LimitValue
Supported index typesDefault primary key _id; user-defined general indexes
Supported data types for index fieldsString, Double, ObjectId, Boolean, Date, 32-bit integer, 64-bit integer, Decimal128
Index field namingLetters, digits, and underscores (_) only; must start with a letter or underscore
Max length per index field128 characters
Max number of index fields10
Max index value size for queries16 KB — queries that exceed this limit may return no results

Flashback scope

LimitValue
Retention period1–7 days
Recovery windowFrom the moment flashback backup takes effect to the current time, within the retention period
Max documents per flashback task1,000 — content beyond this limit is truncated
Restore index key preview max sizeLess than 48 KB
Combined database + collection name lengthLess than 254 characters (e.g., test.table = 10 characters)
Supported size of a single document in query resultsUnlimited

Performance impact

Enabling key-based flashback may reduce the instance's transactions per second (TPS) by up to 3%. The actual impact varies by workload.

Billing

Key-based flashback is free of charge during the public preview period.

Enable flashback backup

  1. Go to the ApsaraDB for MongoDB Replica Set Instances or Sharded Cluster Instances page. In the top navigation bar, select a resource group and region, then click the instance ID.

  2. In the left navigation pane of the instance details page, click Backup and Restoration.

  3. Click the Flashback by key tab.

  4. Click Flashback Backup Settings.

    If an Insufficient Permissions message appears, enter an account and password with read and write permissions for the target database. For details, see Create a database account and grant permissions.
  5. In the Flashback Backup Settings panel, configure the following parameters and click OK.

    ParameterDescription
    Retention periodThe number of days to retain flashback backup files. Valid values: 1–7. The retention timer starts when the backup file is generated and the file is automatically deleted after the specified period.
    Select collection to back upThe collection to enable flashback backup for.
    Preview and set indexes in the collection to back upThe index fields to track for flashback. The default value is _id. Separate multiple fields with commas (,). You can specify up to 10 fields. These are the document fields available as restore keys — they are not related to the indexes returned by getIndexes().
  6. In the Modify Flashback Backup Settings dialog box, click OK.

Important

The configuration takes 10 minutes to take effect. Only data written after this point can be restored using flashback.

Initiate a flashback task

  1. On the Backup and Restoration page, click the Flashback by key tab. In the Actions column of the target backup task, click Point-in-time Flashback.

  2. In the Point-in-time Flashback panel, configure the following parameters and click OK.

    ParameterDescription
    Select collection to restorePre-filled — no change needed.
    Create temporary collectionThe name of the temporary collection where recovered data is written.
    Select point in time for restorationThe point in time to restore data to. The flashback configuration must have been active for at least 10 minutes before a point in time becomes selectable.
    Enter key to restoreThe document keys to restore. See Key syntax below.
  3. In the Flashback Data Preview dialog box, select the documents to restore and click OK. The system displays what will be recovered:

    • Keys separated by semicolons (;) return an OR match — the system shows all documents matching any of the keys.

    • Keys separated by commas (,) return an AND match — if _id is present, the system matches on _id only and ignores other fields in the same set; if no _id is present, the system matches all fields in the set.

After the task completes, the recovered data is available in the temporary collection until the retention period expires.

Key syntax

Use semicolons (;) to separate independent key sets — each set is an OR condition. Use commas (,) within a set to specify AND conditions, using the column=value format. If a key value contains a comma or semicolon, escape it with a backslash (\).

GoalInputPreview
Restore two documents by _idkey1;key2[ { "_id": "key1" }, { "_id": "key2" } ]
Restore by _id AND another fieldkey1;test1=v1,key2[ { "_id": "key1" }, { "test1": "v1", "_id": "key2" } ]
Restore a key that contains a commaa\,b(escape with backslash; e.g., if the primary key is a,b, enter a\,b)
The keys you specify must be included in the index fields you configured when enabling flashback backup. If the input is very long, the system automatically splits the task into multiple flashback tasks — this does not affect the flashback results.

Restore to the original collection

  1. On the Backup and Restoration page, click the Flashback by key tab.

  2. To restore the latest flashback task, click Restore To Original Table. To select a different task, click Flashback Records, find the task, and click restore.

  3. In the Restore To Original Table dialog box, click OK.

    This operation overwrites the matching documents in the original collection with data from the temporary collection. The overwrite takes 1–2 minutes. Do not write to the same keys during this time, or the restored data may not be as expected.
  4. To track the restore job, check Restoration Task Records.

Disable flashback backup

Disable a specific backup task: On the Backup and Restoration page, click the Flashback by key tab. In the Actions column of the target task, click Close.

Disable all backup tasks: On the Backup and Restoration page, click the Flashback by key tab, then click Disable Flashback Backup in the upper-left corner.

Important

After disabling flashback backup, all previously generated flashback backup data becomes unavailable.

Example

This example walks through recovering two documents in the test1.test001 collection that were accidentally modified and deleted.

Step 1: Enable flashback backup

  1. View the current data in the test1.test001 collection.

    image

  2. In Flashback Backup Settings, set the retention period to 1 day, select test001 as the collection to back up, and set _id,name as the index fields.

    image

  3. Wait 10 minutes for the configuration to take effect.

Step 2: Initiate a flashback task

  1. At 2025-08-14T19:27 (UTC+8), two changes are made to test1.test001:

    • The document where name=xiaoli is updated: age is set to 29.

    • The document where name=xiaomi is deleted.

    image

  2. Confirm the changes are now reflected in the collection.

    image

  3. Initiate a flashback task in the console:

    • Set the collection to restore to test001.

    • Set the temporary collection name to temp_flashback_test003.

    • Select a point in time before the changes: 2025-08-14T19:16 (UTC+8).

    • Enter 689d5715fb3153809d4894a1;name=xiaoli as the restore keys.

    The restore index preview shows: [{"_id":"689d5715fb3153809d4894a1"},{"name":"xiaoli"}].

    image

  4. Click OK to preview the flashback data. The preview shows the modification and deletion records from 2025-08-14T19:27 (UTC+8) and the corresponding flashback operations (update and insert).

    image

  5. Select the documents to restore and click OK to start the flashback task.

    image

  6. View the data in the temporary collection. The recovered documents for [{"_id":"689d5715fb3153809d4894a1"},{"name":"xiaoli"}] appear as follows.

    image

Step 3: Restore to the original collection

  1. Click Restore To Original Collection to restore the latest flashback task. Alternatively, click Flashback History and select a specific flashback task to restore from.

    image

    image

  2. Select the latest flashback task and start the restoration.

  3. Click Restore Job History to monitor progress.

    image

  4. Confirm the data in test1.test001 has been restored to its state before the changes at 2025-08-14T19:27 (UTC+8).

    image