MongoDB Atlas Online Archive

MongoDB Atlas Online Archive

Overview

Online Archive automatically moves documents matching an archival rule out of the live Atlas cluster into Atlas-managed object storage, while keeping those documents queryable through the cluster’s FDI endpoint (transparent to the application).

Requirements

Archive Rule Types

DATE (most common)

{
  "criteria": {
    "type": "DATE",
    "dateField": "createdAt",
    "dateFormat": "ISODATE",
    "expireAfterDays": 90
  }
}

dateFormat options: "ISODATE" (default ISODate), "EPOCH_MILLISECONDS", "EPOCH_SECONDS"

CUSTOM Query

{
  "criteria": {
    "type": "CUSTOM",
    "query": "{ \"status\": \"completed\", \"updatedAt\": { \"$lt\": {...} } }"
  }
}

Partition Fields Strategy

Partition fields organize archived data into S3 prefix paths for efficient filtering. Critical for query performance. Choose fields commonly used in query filters:

{
  "partitionFields": [
    { "fieldName": "region",     "order": 0 },
    { "fieldName": "createdAt",  "order": 1 },
    { "fieldName": "customerId", "order": 2 }
  ]
}

Rules:

Archive Job Timing & Processing

Query Routing

When querying via the cluster’s FDI endpoint:

Applications do not need to change query patterns after data is archived — same connection string, same MQL.

Cost Model

Cost Component Rate
Archive Storage ~80-90% cheaper than dedicated cluster storage
Query Processing (archive) $5.00/TB (same as Data Federation)
Data Returned Standard cloud egress

$5/TB cost applies when QUERYING archived data. Storage itself is much cheaper than cluster storage (NVMe/GP3).

Minimum: 10 MB per archive query (no benefit from very small queries).

Restore / Rehydration

Archive data is immutable (append-only). To restore to the live cluster:

// Restore archived data back to the live cluster via $merge
db.archivedCollection.aggregate([
  { $match: { createdAt: { $gte: cutoffDate } } },   // Filter from archive
  { $merge: { into: { db: "mydb", coll: "orders" }, // Rehydrate into live cluster
              on: "_id",
              whenMatched: "keepExisting",
              whenNotMatched: "insert" } }
])

Deciding: Online Archive vs TTL vs Manual S3 Export

Approach Use when
Online Archive Data needs to remain queryable via MQL after tiering; auto-managed pipeline
TTL Index Data can be permanently deleted after expiry (no need to query it)
Manual S3 export via $out Full control over format; downstream Spark/Athena/BigQuery consumption

Limitations

Troubleshooting

Archive Not Moving Data

  1. Check Atlas → Online Archive → [collection] → Activity tab for job status and errors
  2. Verify dateField name is exact (case-sensitive) and matches documents
  3. Confirm correct dateFormatISODATE requires actual ISODate values, not Unix epoch integers
  4. Confirm cluster tier is M10+ and MongoDB version 5.0+

Archive Backlog Growing

  1. Archive jobs process 2 GB per 5-minute window
  2. If data accumulates faster than 2 GB/5 minutes, backlog will grow
  3. Mitigation: narrow the archive rule to reduce concurrent archiving volume, or contact MongoDB for higher throughput

Slow Archive Queries

  1. Partition fields not aligned with query filter → full archive scan
  2. Check partitionFields match the most common query filter fields
  3. Run explain() on the FDI endpoint to check nPartitionsScanned

MACC / Cost Tracking

Archive storage costs appear on the Atlas invoice under Tools & Services → Online Archive. Query processing costs under Data Federation. Monitor in Atlas Billing → Current Invoice.

Anti-Patterns

References