mongoshield copy
Copy databases between deployments, with masking and subsetting.
mongoshield copy [options]Streams documents from --from straight into --to; nothing is stored in between. Shows the plan first. By default nothing is overwritten: the copy stops if a target collection already has documents. --mask anonymises documents on the way (deterministically, so references still match), --subset copies a consistent slice.
Options
Section titled “Options”| Option | Description |
|---|---|
--from <mongodb-uri> | Copy from this deployment (default: the configured source / MONGODB_URI). |
--include <pattern> | Only these namespaces, e.g. app.* or app.users. Repeatable. |
--exclude <pattern> | Skip these namespaces, e.g. *.audit_*. Repeatable. |
--rename <from=to> | Copy under another name, e.g. 'app.*=app_staging.*'. Repeatable. |
--mask <file> | Mask file (e.g. ./mask.ts) applied to every document on its way. |
--mask-secret-env <VAR> | Read the masking secret from this variable when the mask file sets none. Default: MONGOSHIELD_MASK_SECRET. |
--subset <file> | Subset file (e.g. ./subset.ts): filters, and references to follow. |
--mode <fail-if-exists|drop|insert|upsert> | What to do when a target collection already exists. Default: fail-if-exists. |
--drop | Same as --mode drop. |
--dry-run | Show the plan and stop; write nothing. |
--parallelism <n> | Collections copied at the same time (1–64). Default: 4. |
--skip-indexes | Do not create indexes (faster, for throwaway targets). |
--skip-search-indexes | Do not recreate Atlas Search / Vector Search indexes on the target. |
--resume | Continue an interrupted copy from its checkpoint (same options as before). |
--checkpoint <file> | Where the copy records its progress for --resume. Default: .mongoshield/copy-<id>.json. |
--to <mongodb-uri> | Copy into this deployment (required). |
The global options (--config, --json, --quiet,
--verbose, --no-color, --yes) work here too.
Examples
Section titled “Examples”Refresh staging from production, masked:
mongoshield copy --from $PROD_URI --to $STAGING_URI --include 'app.*' --mask ./mask.ts --dropCopy a recent slice under a new name in the same cluster:
mongoshield copy --to $MONGODB_URI --rename 'app.*=app_sample.*' --subset ./subset.tsPreview what would be copied:
mongoshield copy --to $STAGING_URI --mask ./mask.ts --dry-runMongoShield is MIT licensed and is not affiliated with, endorsed by or sponsored by MongoDB, Inc. MongoDB is a trademark of MongoDB, Inc.Privacy policy