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

Open
opened 2026-02-15 20:17:03 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langgraphjs/pull/1928
Author: @Mihailoff
Created: 1/31/2026
Status: 🔄 Open

Base: mainHead: feat/mongodb-ttl-support


📝 Commits (3)

  • 96079da feat(checkpoint-mongodb): add TTL support for automatic checkpoint expiration
  • 1b47f32 chore: add changeset for TTL feature
  • 59e82a4 fix: remove unused import

📊 Changes

5 files changed (+328 additions, -7 deletions)

View changed files

.changeset/mongodb-ttl-support.md (+10 -0)
📝 libs/checkpoint-mongodb/README.md (+27 -0)
📝 libs/checkpoint-mongodb/src/index.ts (+39 -1)
📝 libs/checkpoint-mongodb/src/tests/checkpoints.int.test.ts (+130 -3)
📝 libs/checkpoint-mongodb/src/tests/checkpoints.test.ts (+122 -3)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langgraphjs/pull/1928 **Author:** [@Mihailoff](https://github.com/Mihailoff) **Created:** 1/31/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/mongodb-ttl-support` --- ### 📝 Commits (3) - [`96079da`](https://github.com/langchain-ai/langgraphjs/commit/96079da3f662478b7b8633add3c37c4fd66c84f8) feat(checkpoint-mongodb): add TTL support for automatic checkpoint expiration - [`1b47f32`](https://github.com/langchain-ai/langgraphjs/commit/1b47f324116d45bfc2d93683f86e0bfbd86008d2) chore: add changeset for TTL feature - [`59e82a4`](https://github.com/langchain-ai/langgraphjs/commit/59e82a4c76a8a3c8dc2bfaabac14606c7aba0aa3) fix: remove unused import ### 📊 Changes **5 files changed** (+328 additions, -7 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/mongodb-ttl-support.md` (+10 -0) 📝 `libs/checkpoint-mongodb/README.md` (+27 -0) 📝 `libs/checkpoint-mongodb/src/index.ts` (+39 -1) 📝 `libs/checkpoint-mongodb/src/tests/checkpoints.int.test.ts` (+130 -3) 📝 `libs/checkpoint-mongodb/src/tests/checkpoints.test.ts` (+122 -3) </details> ### 📄 Description 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) ```js // 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 20:17:03 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#1848