Mask data

Make a masked copy of a collection (or mask it in place) with field-level techniques: null out, exclude, shuffle, partial masking, regex, random or fixed values.

Data Masking writes a copy of a collection with sensitive fields hidden or replaced. You can use the copy for tests, demos or analytics. By default, the masked documents go to a new collection named <collection>_masked, and the source is not changed.

A Data Masking tab with one unit for acme_store.customers

Mask a collection

Example: make a safe copy of acme_store.customers.

  1. Right-click customers and choose Mask Collection (on a view: Mask View). You can also use Collection › Mask Collection/View or Data Masking on the global toolbar. A Data Masking tab opens with one unit. Its fields are read from the last 50 documents, and its target is customers_masked.
  2. Open the unit (double-click it, or Edit unit). The Mapping Tree lists every field with its type.
  3. Select email and click Edit mask. In Edit Field Mapping, choose Show only first/last characters, keep 2 first characters, and check the preview.
  4. Select phone and choose Mask entire string. Select birth_date and choose Substitute with random date and time within a range. Select notes and choose Exclude field.
  5. Check JSON Preview: it shows the first documents masked, and nothing is written.
  6. Click Run all units (or Run enabled units) and confirm.

A field that holds several types gets a technique per type. Select several fields to give them the same mask at once.

Choose the target

  • Change Target picks another collection, existing or new, on any connection.
  • Change Source picks another source collection. You can keep the current configuration or create a default one.
  • Click here to overwrite source masks the source collection in place. _id is then never masked. The confirmation says that the source documents will be overwritten.

Safety

  • A run always asks first. The prompt lists each unit (source, target, server). It warns when the target already holds documents: masked documents replace those with the same _id.
  • A target with the read-only lock is refused before the prompt.
  • A target that names the source collection on the same server is refused.
  • If the source and target servers cannot be told apart (a second connection to the same server, an alias, a tunnel), you must type the target’s name to confirm. A run confirmed in advance (a scheduled task, or a command with confirm: true) is refused in that case. Run it from the Data Masking tab instead, or choose another target.
  • Nothing is read or written before the confirmation.

Techniques

TechniqueEffectParameters
Not maskedThe value is written as it is
Null out fieldThe value becomes null
Exclude fieldThe field is left out
ShuffleEach document gets another document’s value; the set of values stays the same
Show only first/last charactersKeeps the first or last characters, masks the othersFirst or last, number of characters
Mask entire stringEvery character is masked
Mask substrings matching regexMasks every match of the regexPattern, flags
Scramble charactersThe same characters in a random order
Replace entire field with a fixed stringA fixed stringValue
Replace entire field with a random stringRandom letters and digitsLength (optional)
Substitute value with fixed numberA fixed number of the same typeValue
Add percentage to numberAdds a fixed percentage, or a random one in a rangePercentage, or interval
Subtract percentage from numberSubtracts a fixed percentage, or a random one in a rangePercentage, or interval
Substitute with random date and timeA random date in the rangeFrom, to
Substitute with fixed date and timeA fixed dateValue
Empty contents of the arrayThe array is emptied
Negate boolean valuetrue becomes false and false becomes true
Substitute with fixed boolean valueA fixed booleanValue
Substitute with new ObjectIdA new ObjectId

Only the techniques that apply to a field’s type are offered. Warn when field value was not changed records an exception when a rule leaves a value as it was.

Other tools of the unit

ToolEffect
Add child / Add siblingAdds a field the scan did not see
Move up / Move downReorders fields in the output
Remove maskLeaves the selected fields unmasked
Show all / masked / unmasked fieldsFilters the tree
Reset ConfigurationRemoves every mask and every field you added. With Rescan the source collection to detect new fields, it reads the source again (Documents to scan (the last ones): 1 to 100,000).
Undo / RedoSteps through your changes
Search configurationsFinds a field or technique in every unit
Exception LogsValues a rule could not handle during the last run
HistoryThe changes made to the unit

The tab can hold several units, one per source collection. Add unit adds one, and Enable unit / Disable unit choose which run with Run enabled units.

Masking during import, export and migration

The import and export wizards also have a Data Masking section with Open field masking editor. Its rules apply to the documents on the way, and the source is not changed (Import data, Export data). So does each unit of a SQL to MongoDB migration (Migrate from SQL to MongoDB).

Save and schedule

Save task keeps the units and their rules. Schedule runs them on a schedule (Automation). A scheduled run of a unit that overwrites its source does so without asking. The task’s confirmation names those units when you schedule it.

Tips

  • Prefer a new target collection: keep Click here to overwrite source for copies you already made.
  • Shuffle keeps realistic values and distributions, but the values are still real. Combine it with other techniques for direct identifiers.

Troubleshooting

ProblemWhat to do
“the target collection is the source collection”Pick another target, or use Click here to overwrite source deliberately.
A field is missing from the treeIt is not in the last documents scanned. Add it with Add sibling, or use Reset Configuration with a rescan of more documents (this removes the masks).
A scheduled masking task did not runIts source and target servers cannot be told apart. Run it from the tab and type the target’s name, or change the target.
Exceptions after a runOpen Exception Logs: the values a technique could not handle (for example, text in a number field).