Skip to content

feat(checkpoint-mongodb): add TTL support for automatic checkpoint data expiration#1928

Open
Mihailoff wants to merge 3 commits intolangchain-ai:mainfrom
Mihailoff:feat/mongodb-ttl-support
Open

feat(checkpoint-mongodb): add TTL support for automatic checkpoint data expiration#1928
Mihailoff wants to merge 3 commits intolangchain-ai:mainfrom
Mihailoff:feat/mongodb-ttl-support

Conversation

@Mihailoff
Copy link

Add optional TTL parameter to MongoDBSaver that enables automatic expiration of checkpoints using MongoDB's TTL indexes.

  • Add ttl option to MongoDBSaverParams (value in seconds)
  • Add setup() method to create TTL indexes, returns Error[] for caller to handle failures
  • Add upserted_at timestamp to documents when TTL is enabled
  • Each write refreshes TTL (expires after inactivity, not creation)
  // Create checkpointer with 1-hour TTL (in seconds)                         
  const checkpointer = new MongoDBSaver({                                     
    client,                                                                   
    ttl: 3600,                                                                
  });                                                                         
                                                                              
  // Create TTL indexes (call on startup/deployment)                          
  const errors = await checkpointer.setup();                                  
  if (errors.length) {                                                        
    console.warn("Failed to create TTL indexes:", errors);                    
  } 

Fixes # (issue)

Ever growing records in database.

…piration

Add optional TTL parameter to MongoDBSaver that enables automatic
expiration of checkpoints using MongoDB's TTL indexes.

- Add `ttl` option to MongoDBSaverParams (value in seconds)
- Add `setup()` method to create TTL indexes, returns Error[] for
  caller to handle failures
- Add `upserted_at` timestamp to documents when TTL is enabled
- Each write refreshes TTL (expires after inactivity, not creation)
@changeset-bot
Copy link

changeset-bot bot commented Jan 31, 2026

🦋 Changeset detected

Latest commit: 59e82a4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@langchain/langgraph-checkpoint-mongodb Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@hntrl @dqbd mind taking a 2nd look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants