---
name: "mongodb-change-streams-reactive"
description: "Stream real-time insert, update, and delete mutations from MongoDB replica set oplogs."
metadata:
  author: "MongoDB"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "listen to mongodb change streams"
  - "resume mongodb change stream"
  - "stream oplog mutations"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# MongoDB Change Streams & Real-Time Sync

Implements event-driven notifications with MongoDB Change Streams: filtering with match pipelines, resume tokens (resumeAfter), fullDocument lookup options, and feeding search indexes or webhooks.

## When to Invoke
Invoke this skill whenever you need to:
- listen to mongodb change streams
- resume mongodb change stream
- stream oplog mutations

## Execution SOP & Rules
1. Initialize change stream on collection: cursor = collection.watch([{'$match': {'operationType': 'update'}}]).
2. Set fullDocument='updateLookup' to receive the complete updated document state alongside the delta.
3. Persist event._id resume token to Redis or local disk upon successful message processing.
4. Re-open stream passing resumeAfter: savedResumeToken to gracefully resume after network disconnections.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
