# MongoServerError: change stream resume token invalid for namespace 'mydb.mycoll': token belongs to different database

- **ID:** `mongodb/change-stream-resume-token-invalid-namespace`
- **Domain:** mongodb
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 87%

## Root Cause

The resume token provided to open a change stream was generated from a different database or collection than the one being watched, causing a namespace mismatch.

## Workarounds

1. **Open a new change stream without a resume token (e.g., db.collection.watch([], {startAtOperationTime: Timestamp(1, 1)})) to start from the earliest possible point, then capture a fresh token for future resumption.** (85% success)
   ```
   Open a new change stream without a resume token (e.g., db.collection.watch([], {startAtOperationTime: Timestamp(1, 1)})) to start from the earliest possible point, then capture a fresh token for future resumption.
   ```
2. **If the token is from a different namespace, construct a new change stream on the correct namespace using db.collection.watch() and ignore the old token. Example in Node.js: const changeStream = collection.watch(); changeStream.on('change', (change) => { console.log(change._id); });** (90% success)
   ```
   If the token is from a different namespace, construct a new change stream on the correct namespace using db.collection.watch() and ignore the old token. Example in Node.js: const changeStream = collection.watch(); changeStream.on('change', (change) => { console.log(change._id); });
   ```

## Dead Ends

- **** — Reusing a resume token from a different replica set or sharded cluster (e.g., from production in a test environment) still fails because the token is cluster-specific. (90% fail)
- **** — Manually editing the resume token's namespace field in the application code does not work because the server validates the token against internal metadata. (95% fail)
