Course outline

MongoDB / Advanced: distributed and recoverable operations / Lesson 21

TTL indexes and delayed deletion

Design expiration as background cleanup while enforcing validity in the application.

About 22 min read20 worked examples20 practice exercisesContent reviewed
On this page

Lesson goals

  • Explain TTL index requirements and asynchronous deletion.
  • Inspect a disposable expiry fixture and index.
  • Test validity, capacity, and recovery without relying on immediate deletion.
  • Calculate TTL eligibility from a BSON date and interval without asserting deletion time.
  • Design independently verifiable validity, monitoring and retention changes.

Separate validity from deletion

A session can become invalid at a specific time even if its document remains stored briefly afterwards. A TTL index helps remove eligible documents in the background; deletion is not guaranteed at the exact expiry instant. The application must check its own validity and authorization rules rather than assume that document presence means a session is valid. Define timezone, retention, and recovery requirements before enabling cleanup.

Create a disposable expiry example

The following mongosh commands are illustrative for a new disposable MongoDB 8.0-compatible collection. The date is synthetic and does not imply the current time or a measured deletion. The TTL index uses a date field and zero seconds to express an absolute expiration time. Do not create an index on a configured collection without an approved retention and capacity plan.

javascript Create a TTL index and synthetic session
db.lab_sessions.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 0 });
db.lab_sessions.insertOne({ _id: 1, user: "training", expiresAt: ISODate("2030-01-01T00:00:00Z") });

The document has a BSON date in expiresAt. Its eligibility depends on the server’s time and TTL behavior; the example does not assert that it exists or has been deleted at any particular time.

Inspect the definition and document

Read the index definition and the sample document in the isolated lab. An absent document can have several explanations, including deletion or expiry, and a present expired document is not proof of validity. Confirm the date type and configured TTL option, then compare them with the application’s session check. Results are environment-dependent and can change between the two reads.

javascript Inspect the lab index and session
db.lab_sessions.getIndexes();
db.lab_sessions.find({ _id: 1 }, { _id: 1, expiresAt: 1 });

These read-only operations show the collection’s indexes and any current matching document. They do not force TTL cleanup or guarantee a fixed output. Use the deployed version’s documentation to interpret the index options.

Plan the cleanup workload

TTL cleanup is background work and may lag under workload. A large existing eligible population can create substantial delete activity after an index is introduced or a retention period is shortened. Rehearse on representative isolated data, monitor storage and workload impact, and plan capacity before rollout. Confirm the documented restrictions for the target collection type, including any time-series-specific rules, rather than assuming all TTL indexes behave identically.

Test validity and delayed removal

Test a valid session, an expired but still present document, a missing date, and an already removed document using controlled synthetic data. Verify that the application denies an expired session independent of background deletion. Monitor deletion progress over a suitable interval without asserting an exact second. Document backup and restore implications: restoring historical data may reintroduce documents that need to be evaluated under the active TTL policy.

Calculate eligibility separately from deletion

For an ordinary collection with a TTL index on a BSON Date field, the expiration threshold is the indexed date plus expireAfterSeconds. With expireAfterSeconds:0 the date itself represents an absolute expiration threshold. A document becomes eligible when that threshold is reached, but eligibility is not the same as the exact deletion time. The TTL monitor works in the background and deletion can lag due to scheduling and workload. Never use the presence of an expired document as proof that the application should accept a session or token.

Define the clock and boundary in the business contract. An authorization check should independently require the session to be unexpired at the decision instant, alongside identity and other conditions. Test a future date, a boundary date, an expired-but-present record and an already removed record. A hypothetical timestamp calculation can establish eligibility under the stated assumptions; it cannot prove when a real server deleted anything. All examples in this lesson are synthetic and no index or database action is performed.

Validate the indexed date shape

TTL depends on the indexed field containing a BSON date or an array containing date values. A missing field or a value with no BSON date does not expire under that TTL index. A string that looks like an ISO date is not automatically a BSON Date. Validate both presence and type at the application or schema boundary, and inventory malformed historical records separately. If the field is an array with multiple dates, MongoDB uses the earliest date to calculate expiration; do not assume the latest renewal date controls cleanup.

A normal TTL index is single-field; compound indexes do not support TTL and the _id field cannot be a TTL index. The allowed expireAfterSeconds range and collection-specific restrictions must be checked against the versioned documentation. Time-series collections have bucket-based expiry behavior and their own options and restrictions; do not apply a simple per-document deadline model to a bucket without checking those rules. The examples identify ordinary or time-series scope explicitly.

Interpret background cleanup evidence

MongoDB documents that the TTL background task runs periodically, but it does not guarantee deletion immediately when a document expires. Workload and the volume of eligible documents can add delay beyond the scheduling interval. A document still present shortly after its threshold is therefore not by itself proof of a broken index. Inspect the configured TTL index, BSON type, server time, eligibility, primary status and cleanup metrics over an appropriate interval. Avoid promising deletion at a specific second or treating one observation as a complete diagnosis.

Metrics such as TTL passes and deleted documents can help establish progress, but a rising total does not prove that a particular business record was deleted or that the service enforced validity on time. Verify representative record identities and the application’s expired-but-present behavior independently. A missing document can have several causes, including a separate delete or retention cleanup; reconcile evidence rather than attributing it automatically to TTL. Review privileges and protect sensitive operational information when sharing diagnostics.

Plan retention changes and load

Reducing expireAfterSeconds can make a large existing population immediately eligible, creating background delete work and resource pressure. Before changing the policy, estimate the affected population, rehearse with representative isolated data, verify backups and define monitoring, capacity and rollback or forward-repair criteria. MongoDB documents collMod for changing expireAfterSeconds on an existing TTL index; calling createIndex with the same key is not the method for changing that option. This lesson describes the boundary only and does not issue administrative commands.

Raising the interval changes future eligibility but cannot restore documents that have already been deleted. A restore of historical data can reintroduce records that are already eligible under the active TTL rule, so plan the restore destination and validation sequence with that interaction in mind. Retention, privacy and recovery requirements can conflict: document the approved policy and reconcile it with backup retention. A faster cleanup is not automatically a correct policy if it removes data needed for recovery or audit.

Test validity, eligibility and recovery independently

Build a synthetic fixture with valid future and past BSON dates, an exact boundary, a missing field, a string date and an array of dates. Calculate expected eligibility from a fixed assumed server time and the configured interval, then test application authorization separately. Include a record that is expired but still present: its continued storage must not make it valid. For a date array, calculate from the earliest date and verify that the result matches the intended retention contract. Do not infer actual deletion from these hand calculations.

An isolated operational rehearsal should inspect the real index definition, progress metrics and document identities over time without demanding an exact deletion second. Include a retention reduction, an unexpectedly large eligible population and a restore of historical data. Record the target server version, topology, time assumptions and observed evidence, and distinguish hypothetical expectations from measured results. Verify how the service handles missing or malformed dates and how operators recover from a mistaken retention policy before cutover.

20 worked examples

1. Absolute expiration in the past

Problem: Is this ordinary document eligible at the assumed time?

  1. With zero seconds the indexed date is the threshold.
  2. The assumed time is five minutes after that threshold, so the document is eligible but not guaranteed deleted.
text Hypothetical time and retention fixture
expiresAt: BSON Date 12:00 UTC
expireAfterSeconds: 0
assumed server time: 12:05 UTC

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Eligible; actual deletion time is unspecified.

Why this result follows: The assumed time is five minutes after that threshold, so the document is eligible but not guaranteed deleted.

2. Absolute expiration in the future

Problem: Is a future deadline eligible now?

  1. The threshold is the indexed date at 12:10.
  2. The assumed time is five minutes earlier than that threshold.
text Hypothetical time and retention fixture
expiresAt: BSON Date 12:10 UTC
expireAfterSeconds: 0
assumed server time: 12:05 UTC

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Not yet eligible under this TTL rule.

Why this result follows: The assumed time is five minutes earlier than that threshold.

3. Relative retention

Problem: When does this date plus interval expire?

  1. Six hundred seconds equals ten minutes after the indexed date.
  2. The threshold is 12:10, one minute after the assumed time.
text Hypothetical time and retention fixture
createdAt: BSON Date 12:00 UTC
expireAfterSeconds: 600
assumed server time: 12:09 UTC

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Threshold 12:10; not yet eligible.

Why this result follows: The threshold is 12:10, one minute after the assumed time.

4. Exact threshold

Problem: What is the eligibility at the stated boundary?

  1. The indexed date plus zero seconds is exactly 12:00.
  2. At the stated threshold the record is eligible, but background deletion is not guaranteed at that instant.
text Hypothetical time and retention fixture
expiresAt: BSON Date 12:00 UTC
expireAfterSeconds: 0
assumed server time: 12:00 UTC

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Eligible at the threshold; deletion may occur later.

Why this result follows: At the stated threshold the record is eligible, but background deletion is not guaranteed at that instant.

5. Expired but present

Problem: Should this session be accepted?

  1. The declared expiry precedes the decision time by five minutes.
  2. The application’s validity rule rejects the session independently of background deletion.
text Hypothetical time and retention fixture
session expiresAt: 12:00 UTC
assumed decision time: 12:05 UTC
document: still present
policy: expiresAt must be later than decision time

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Reject the expired session.

Why this result follows: The application’s validity rule rejects the session independently of background deletion.

6. Missing TTL field

Problem: Can this document expire through the stated index?

  1. The document has no indexed expiration field.
  2. MongoDB documents that a missing indexed field does not expire through that TTL rule.
text Hypothetical time and retention fixture
ordinary document: {_id:1}
TTL index field: expiresAt
expiresAt: missing

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: No TTL expiration for this missing field.

Why this result follows: MongoDB documents that a missing indexed field does not expire through that TTL rule.

7. String date

Problem: Does ISO-looking text meet the BSON Date requirement?

  1. The stored value is explicitly a BSON string, not a BSON Date.
  2. A field with no date value does not expire through the stated TTL index.
text Hypothetical time and retention fixture
document: {expiresAt:'2030-01-01T00:00:00Z'}
field type: BSON string
TTL field: expiresAt

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: The string alone does not make the record eligible.

Why this result follows: A field with no date value does not expire through the stated TTL index.

8. Date array uses earliest

Problem: Which date determines the threshold?

  1. MongoDB uses the earliest date in an indexed date array for expiry.
  2. The earliest threshold is 12:00, already passed at the assumed time.
text Hypothetical time and retention fixture
expiresAt: [BSON Date 12:00, BSON Date 12:30] UTC
expireAfterSeconds: 0
assumed server time: 12:15 UTC

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Eligible based on 12:00, not 12:30.

Why this result follows: The earliest threshold is 12:00, already passed at the assumed time.

9. Array without date

Problem: Does an array of strings expire?

  1. The array contains no BSON date values under the stated types.
  2. The TTL rule cannot calculate expiration from date-like strings alone.
text Hypothetical time and retention fixture
expiresAt: ['2030-01-01','2030-02-01']
all elements: BSON strings
TTL field: expiresAt

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: The document does not expire through this TTL field.

Why this result follows: The TTL rule cannot calculate expiration from date-like strings alone.

10. Compound TTL restriction

Problem: Does this compound key support TTL?

  1. MongoDB TTL indexes are single-field indexes.
  2. A compound index does not support TTL and ignores the expiration option.
text Hypothetical time and retention fixture
index key: {tenant:1,expiresAt:1}
option: expireAfterSeconds:0
collection: ordinary

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: This compound key does not provide TTL deletion.

Why this result follows: A compound index does not support TTL and ignores the expiration option.

11. Identifier restriction

Problem: Can _id be the TTL index field?

  1. MongoDB documents that the _id field does not support TTL indexes.
  2. A separate suitable date field and retention design are required.
text Hypothetical time and retention fixture
proposed TTL key: {_id:1}
expireAfterSeconds: 0
collection: ordinary

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: The proposed _id TTL index is unsupported.

Why this result follows: A separate suitable date field and retention design are required.

12. Delayed deletion is not failure alone

Problem: Does one late observation diagnose a broken index?

  1. TTL cleanup is asynchronous and can lag after eligibility.
  2. The single observation lacks index, type, clock and progress evidence needed for diagnosis.
text Hypothetical time and retention fixture
threshold: 12:00
observation: document present at 12:00:10
index and workload: not inspected

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Investigate over an appropriate interval; do not infer failure yet.

Why this result follows: The single observation lacks index, type, clock and progress evidence needed for diagnosis.

13. Deletion metric is aggregate

Problem: Does a rising TTL deletion counter prove ID 7 was deleted?

  1. The metric counts TTL deletions in aggregate, not the identities in this scenario.
  2. A rise of five does not identify whether document 7 was among them.
text Hypothetical time and retention fixture
metrics.ttl.deletedDocuments: increases by 5
target document: _id 7
identity evidence: absent

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Check the target identity and relevant evidence separately.

Why this result follows: A rise of five does not identify whether document 7 was among them.

14. Reducing retention

Problem: What happens to eligibility when the interval is shortened?

  1. The old threshold is 13:00 and the new threshold is 12:30.
  2. At 12:40 the record changes from not yet eligible to eligible under the new rule.
text Hypothetical time and retention fixture
createdAt: 12:00 UTC
assumed time: 12:40 UTC
old interval: 3600 s; new interval: 1800 s

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: The shortened rule makes this record eligible.

Why this result follows: At 12:40 the record changes from not yet eligible to eligible under the new rule.

15. Increasing retention cannot undo deletion

Problem: Does a longer interval restore a deleted record?

  1. The retention option affects eligibility of records that still exist.
  2. Changing it does not recreate a document already removed from the collection.
text Hypothetical time and retention fixture
record: already deleted
old interval: 600 s
new interval: 3600 s

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Recovery requires a separate suitable backup or source.

Why this result follows: Changing it does not recreate a document already removed from the collection.

16. Large eligible population

Problem: Why estimate affected records before reducing retention?

  1. The proposed rule changes eligibility for a large declared population.
  2. Background deletion can create substantial load, and the actual impact requires an isolated rehearsal.
text Hypothetical time and retention fixture
existing documents: 100000
new rule makes 80000 eligible (assumed)
cleanup capacity: not measured

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Plan capacity and monitor; no delete rate is claimed.

Why this result follows: Background deletion can create substantial load, and the actual impact requires an isolated rehearsal.

17. Change existing TTL option

Problem: Which documented mechanism changes the interval?

  1. The same key pattern already has a TTL index.
  2. MongoDB documents collMod for changing its expireAfterSeconds rather than createIndex with the same key.
text Hypothetical time and retention fixture
existing single-field TTL index: {expiresAt:1}
old expireAfterSeconds: 3600
new requested value: 1800

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Review the authorized collMod procedure; none is executed.

Why this result follows: MongoDB documents collMod for changing its expireAfterSeconds rather than createIndex with the same key.

18. Restored expired data

Problem: What can happen after restoring historical records under an active TTL rule?

  1. The restored date is one hour before the assumed server time.
  2. The record is eligible under the active rule and may be removed by later background cleanup.
text Hypothetical time and retention fixture
restored expiresAt: 12:00 UTC
assumed server time: 13:00 UTC
expireAfterSeconds: 0
TTL index: active

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Plan isolated validation before TTL cleanup affects the fixture.

Why this result follows: The record is eligible under the active rule and may be removed by later background cleanup.

19. Time-series bucket boundary

Problem: When is this synthetic bucket eligible under the stated rule?

  1. Five minutes after the bucket upper timestamp is 12:15.
  2. At 12:14 the stated bucket threshold has not yet been reached.
text Hypothetical time and retention fixture
collection: time series
bucket upper timestamp: 12:10 UTC
expireAfterSeconds: 300
assumed time: 12:14 UTC

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Threshold 12:15; not yet eligible.

Why this result follows: At 12:14 the stated bucket threshold has not yet been reached.

20. Unknown cause of absence

Problem: Can a missing document be attributed to TTL alone?

  1. The current read establishes only that the document is not returned.
  2. Other deletion paths are not ruled out, so the TTL index alone does not identify the cause.
text Hypothetical time and retention fixture
document _id: 9
current read: no match (assumed)
TTL index: present
other delete evidence: unknown

The calculation is reasoned from the assumptions; no index or deletion was executed.

Expected result: Reconcile audit and operational evidence.

Why this result follows: Other deletion paths are not ruled out, so the TTL index alone does not identify the cause.

Common errors and fixes

An expired session is accepted while its document remains.

Why it happens
The application treats document presence as validity.
How to fix it
Check the expiration timestamp as part of authorization.
Prevent it next time
Test expired-but-present documents.

A document without the expected date persists.

Why it happens
The TTL rule cannot use the intended date value when the field is missing or unsuitable.
How to fix it
Validate the field and correct data using an approved procedure.
Prevent it next time
Test field type and presence at write time.

A retention change causes unexpected delete load.

Why it happens
A large existing population became eligible for background cleanup.
How to fix it
Follow the deployment’s capacity and recovery procedure.
Prevent it next time
Estimate and rehearse the eligible population before changing policy.

20 practice exercises

1. Does a document remaining after its expiry time prove TTL has failed?

Show hint

Separate eligibility from the background deletion schedule.

Show worked solution

No. TTL deletion is asynchronous and can lag. Check the index, date, server time, workload, and documented behavior over an appropriate interval.

A document remaining after expiry does not by itself prove TTL failed because deletion is asynchronous. Inspect the index, date type, server time, progress and workload over an appropriate interval.

Check your solution

  • Deletion at the exact instant is not assumed.
  • The index, date and cleanup progress are inspected.

2. Should a session be accepted merely because its expired document still exists?

Show hint

Determine validity at decision time rather than document presence.

Show worked solution

No. The application must enforce the session’s validity and authorization independently of the cleanup schedule.

The application must reject an expired session under its contract even if TTL has not removed it. Check time, identity and other authorization conditions independently of cleanup.

Check your solution

  • An expired-but-present session is rejected.
  • The decision does not depend on TTL deletion timing.

3. At assumed 12:05 UTC, compare BSON expiration dates 12:00 and 12:10 with expireAfterSeconds:0. State eligibility and deletion limits.

Show hint

Zero makes each indexed date its threshold.

Show worked solution

The 12:00 record is eligible and the 12:10 record is not yet eligible. Neither calculation specifies an exact deletion time; TTL cleanup is asynchronous.

Check your solution

  • Only the 12:00 record is eligible.
  • No exact deletion time is claimed.

4. A BSON createdAt is 12:00 and expireAfterSeconds is 900. Compare eligibility at 12:14 and 12:16.

Show hint

Convert seconds to minutes and add them to the date.

Show worked solution

Nine hundred seconds is fifteen minutes, so the threshold is 12:15. The document is not yet eligible at 12:14 and is eligible at 12:16; actual cleanup may occur later.

Check your solution

  • The threshold is 12:15.
  • Eligibility differs at the two assumed times.

5. At 12:00 a session expires exactly at 12:00, and the contract requires expiresAt greater than decision time. Decide authorization and TTL eligibility.

Show hint

The business predicate uses a strict greater-than boundary.

Show worked solution

The equality fails the application’s greater-than validity rule, so the session is rejected. With a zero-second TTL interval it is eligible at that threshold, but it may remain stored until background deletion.

Check your solution

  • The session is rejected at the boundary.
  • Eligibility does not guarantee immediate deletion.

6. A session expired at 12:00 but remains stored at 12:05. Compare the application decision with the TTL diagnostic conclusion.

Show hint

Validity and cleanup are independent decisions.

Show worked solution

Reject the session if the application contract requires an unexpired date. Its presence alone does not prove TTL failed; inspect the index, BSON type, server time and cleanup progress over a suitable interval.

Check your solution

  • The expired session is rejected.
  • A single late observation is not called a TTL failure.

7. Compare missing expiresAt, a BSON string date, and a BSON Date for TTL eligibility.

Show hint

TTL uses BSON date values, not date-looking text.

Show worked solution

The missing field and string contain no BSON date and do not expire through that index. The BSON Date can determine a threshold; compare it plus the interval with the assumed server time to determine eligibility.

Check your solution

  • Missing and string values lack a usable BSON date.
  • The BSON Date is assessed against time and interval.

8. Two indexed date arrays are A=[12:00,12:40] and B=[12:15,12:45], with expireAfterSeconds:600. At assumed 12:20, compare eligibility and the latest-date policy risk.

Show hint

Add ten minutes to the earliest date in each array.

Show worked solution

A’s earliest-date threshold is 12:10, so A is eligible; B’s is 12:25, so B is not yet eligible. If the application intends the latest renewal to control retention, neither array should be interpreted using that assumption without redesign.

Check your solution

  • A is eligible at 12:20.
  • B is not yet eligible because its threshold is 12:25.

9. Compare index keys {expiresAt:1} and {tenant:1,expiresAt:1} with expireAfterSeconds:0 for ordinary TTL.

Show hint

TTL indexes are single-field.

Show worked solution

The single-field date index can implement the stated TTL rule subject to its other requirements. The compound index does not support TTL and ignores the expiration option, although it may serve a different query purpose.

Check your solution

  • The TTL candidate is single-field.
  • The compound key does not provide TTL cleanup.

10. A proposed TTL index uses _id, while the application needs expiration at expiresAt. Explain the restriction and a suitable design direction.

Show hint

The _id field does not support TTL indexes.

Show worked solution

Do not use _id as the TTL field. Review a separate single-field TTL index on the validated BSON expiresAt date, and enforce session validity in the application independently of cleanup.

Check your solution

  • The _id TTL proposal is rejected.
  • A validated expiration date and separate validity check are specified.

11. Two expired-looking records remain: A has a valid BSON Date and B has a string. Compare the first diagnostic hypothesis for each without assuming deletion timing.

Show hint

Check type before interpreting cleanup delay.

Show worked solution

A may be eligible but awaiting asynchronous cleanup, so inspect the active index and progress. B has no BSON date and does not expire through that TTL field; validate or correct its type under an approved procedure.

Check your solution

  • A is not declared a TTL failure from presence alone.
  • B’s string type is identified as unsuitable.

12. TTL deletedDocuments rises by 10, but document 7 is absent. Explain what remains uncertain.

Show hint

An aggregate counter does not identify individual records.

Show worked solution

The counter indicates aggregate TTL deletion progress, but does not prove that ID 7 was one of those deletions. Reconcile the record’s identity and other delete or audit evidence before attributing the cause.

Check your solution

  • The counter is not treated as per-ID proof.
  • Other deletion evidence is reviewed.

13. At 12:40 records A and B were created at 12:00 and 12:20. Compare eligibility under old 3600-second and proposed 1800-second retention.

Show hint

Calculate a threshold for each record under each rule.

Show worked solution

Under 3600 seconds neither is eligible: their thresholds are 13:00 and 13:20. Under 1800 seconds A’s threshold is 12:30 and has passed, while B’s is 12:50 and has not; estimate the full population before changing policy.

Check your solution

  • Neither record is eligible under the old rule.
  • Only A is eligible under the proposed rule.

14. Retention option A would make 80,000 existing documents eligible and option B would make 10,000 eligible. Design a comparison without assuming either cleanup rate or policy acceptability.

Show hint

Eligibility volume, capacity and business retention all matter.

Show worked solution

Reconcile each eligible population against approved retention requirements, then rehearse representative cleanup and measure resource impact in isolation. Compare backup and recovery needs and choose only after explicit capacity and policy gates; neither count predicts an exact deletion time.

Check your solution

  • Both populations are checked against retention policy.
  • Capacity and recovery are tested without a promised deletion rate.

15. An existing TTL index has expireAfterSeconds 3600. Explain how to review a requested change to 1800 without calling createIndex again.

Show hint

MongoDB documents collMod for this option change.

Show worked solution

Review the version-specific collMod procedure, affected eligible population, backup and monitoring plan. Do not run it against a configured service as part of this exercise; createIndex with the same key does not change the existing option.

Check your solution

  • collMod is identified as the documented mechanism.
  • No infrastructure change is performed.

16. A record was deleted under a 600-second TTL rule, then retention is increased to 3600 seconds. Explain recovery options.

Show hint

A configuration change does not recreate removed data.

Show worked solution

The deleted record remains absent after the interval increases. Recover it only through an approved suitable backup or source and account for the active TTL policy during isolated restoration.

Check your solution

  • Increasing retention does not restore the record.
  • A separate recovery source is required.

17. An isolated restore contains A expiresAt 12:50 and B expiresAt 13:20, both BSON dates; assumed server time is 13:00 and TTL interval is zero. Compare eligibility and plan validation.

Show hint

A restored record may already be eligible under the active index.

Show worked solution

A is eligible because 12:50 has passed; B is not yet eligible because 13:20 is future. In an authorized isolated restore, account for the active TTL policy when validating both records and do not assume an exact removal time.

Check your solution

  • A is eligible and B is not yet eligible.
  • The isolated validation plan accounts for active TTL.

18. A time-series bucket upper timestamp is 12:10 and expireAfterSeconds is 300. Compare assumed times 12:14 and 12:16.

Show hint

Add five minutes to the bucket upper timestamp.

Show worked solution

The stated bucket threshold is 12:15. It has not arrived at 12:14 and has passed at 12:16; background removal can still lag and the time-series procedure has its own restrictions.

Check your solution

  • The threshold is 12:15.
  • No exact removal instant is asserted.

19. A record is missing and a TTL index exists, but another delete process also runs. Design an attribution check.

Show hint

Absence does not identify the deleting mechanism.

Show worked solution

Inspect authorized audit and operational evidence for the record’s stable identity, TTL progress and the other delete process. Do not attribute the absence solely to TTL without evidence connecting that record to the mechanism.

Check your solution

  • The record identity is reconciled.
  • Other deletion paths are investigated.

20. At assumed 12:00 UTC and TTL interval zero, design and classify five session fixtures: A BSON date 12:10, B BSON date 11:50 and still present, C missing date, D string "11:50", E BSON date array [11:55,12:30]. The application requires expiresAt greater than decision time and accepts only a scalar BSON date.

Show hint

Separate TTL’s date-array rule from the application’s scalar validity rule.

Show worked solution

A is not yet TTL-eligible and passes the stated time/type rule. B is eligible but must be rejected despite remaining present. C and D have no BSON date for TTL and fail the application type/presence contract. E is TTL-eligible from 11:55 but fails the application scalar-date contract. These are reasoned outcomes, not observed deletions.

Check your solution

  • A is not eligible; B and E are eligible.
  • C and D lack TTL date values; B, C, D and E fail the stated application contract.

Key takeaways

  • TTL deletion is asynchronous, not an exact-time validity check.
  • Validate BSON date fields and monitor cleanup workload.
  • Rehearse retention changes and restore behavior.
  • Eligibility and background deletion are different moments.
  • The earliest date in a date array determines the expiration calculation.
  • Increasing retention does not restore already deleted documents.

Official references