Skip to content

mongoshield find

Search a backup for documents, and restore just those.

Terminal window
mongoshield find [backup] <namespace> [filter] [options]

Searches one collection of a backup with a MongoDB filter, without restoring it. The filter is Extended JSON: '{"_id":{"$oid":"…"}}', '{"age":{"$gte":18}}'. Supported: equality, $eq $ne $gt $gte $lt $lte $in $nin $exists $type $regex $and $or $nor $not $elemMatch $size. With --restore, the matching documents are written back (insert skips documents whose _id exists; upsert replaces them).

ArgumentDescription
[backup]optionalBackup id, or "latest" (default)
<namespace>requiredThe collection to search, e.g. app.users
[filter]optionalMongoDB filter as Extended JSON (default: {})
OptionDescription
--from <storage-url>Where backups are stored: ./dir, file:///abs, s3://bucket/prefix (default: config).
--limit <n>Stop after n matching documents (default: no limit).
--projection <json>Only these fields, e.g. '{"name":1,"email":1}' (or 0 to drop fields).
--identity-file <path>age identity file for encrypted backups (from mongoshield keygen). Repeatable.
--passphrase-env <VAR>Read the encryption passphrase from this environment variable.
--restoreWrite the matching documents to the target.
--to-uri <mongodb-uri>With --restore: the deployment to write to (default: the configured source).
--to-namespace <db.collection>With --restore: the collection to write to (default: the same namespace).
--mode <insert|upsert>With --restore: insert (skip existing _id) or upsert (replace them). Default: insert.
--createWith --restore: create the target collection if it does not exist.
--dry-runWith --restore: count what would be written, and write nothing.

The global options (--config, --json, --quiet, --verbose, --no-color, --yes) work here too.

Find a user in the latest backup:

Terminal window
mongoshield find app.users '{"email":"ada@example.com"}'

Find by ObjectId in a specific backup, as type-preserving JSON:

Terminal window
mongoshield find 2026-10-20T03-00-04Z_7f3a9c app.users '{"_id":{"$oid":"6523f1c2a1b2c3d4e5f60718"}}' --json

Put back orders deleted by mistake (keeps the ones that still exist):

Terminal window
mongoshield find app.orders '{"customerId":42,"createdAt":{"$gte":{"$date":"2026-10-01T00:00:00Z"}}}' --restore

Preview restoring into a side collection:

Terminal window
mongoshield find app.users '{"tags":"vip"}' --restore --to-namespace app.users_restored --create --dry-run