Skip to content

mongoshield copy

Copy databases between deployments, with masking and subsetting.

Terminal window
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.

OptionDescription
--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.
--dropSame as --mode drop.
--dry-runShow the plan and stop; write nothing.
--parallelism <n>Collections copied at the same time (1–64). Default: 4.
--skip-indexesDo not create indexes (faster, for throwaway targets).
--skip-search-indexesDo not recreate Atlas Search / Vector Search indexes on the target.
--resumeContinue 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.

Refresh staging from production, masked:

Terminal window
mongoshield copy --from $PROD_URI --to $STAGING_URI --include 'app.*' --mask ./mask.ts --drop

Copy a recent slice under a new name in the same cluster:

Terminal window
mongoshield copy --to $MONGODB_URI --rename 'app.*=app_sample.*' --subset ./subset.ts

Preview what would be copied:

Terminal window
mongoshield copy --to $STAGING_URI --mask ./mask.ts --dry-run