Data Masking
Protect sensitive data during export by applying masking transformations. Data masking allows you to export data for development, testing, or analytics while obscuring personally identifiable information (PII) and other sensitive fields. Essential for GDPR, HIPAA, and SOC 2 compliance.
Apply data masking to your exports:
Data masking is critical for several scenarios:
VisuaLeaf ships with seven built-in masking techniques. Pick per field, per export — and mix techniques within a single job when different columns need different treatment.
| Technique | Description | Input | Output |
|---|---|---|---|
| partial | Reveal the first / last N characters and mask the rest. Preserves format recognition. | john@example.com |
j***@e***.com |
| hash | Deterministic SHA-256 hash. Same input always produces the same output, so joins and referential integrity survive. | john@example.com |
a8f5f167f44f4964... |
| fake | Faker-style realistic replacement (names, addresses, phones, emails, companies). Great for demo and QA data. | John Smith |
Jane Wilson |
| null | Write a literal NULL in place of the value. Good for optional fields the target system doesn't need. |
secret123 |
null |
| truncate | Drop the field entirely from the exported document. Nothing is written — the safest option for high-risk fields. | ssn: "123-45-6789" |
(field removed) |
| redact | Replace with a solid mask. No information about the original value survives. | password! |
******** |
| randomize | Replace with a random value of the same type and length. Different every run — use when you need uniqueness but not repeatability. | 555-123-4567 |
872-410-3391 |
Deterministic vs. non-deterministic: hash is the only deterministic technique — the same input always yields the same output. Use it whenever you need masked data to still join across collections or across export runs. Use randomize or fake when you specifically want the output to change each run.
Masking is expressed as a JSON policy attached to each export job. Every field can pick one technique and, optionally, a condition that decides when to apply it. Policies run inside VisuaLeaf on the exported records — your MongoDB collections are never modified.
You need to export users and orders to a data-warehouse for analytics. Real emails must never leave production, but the analytics team still needs to join a user's orders.customerEmail back to users.email. hash is the right pick — deterministic SHA-256 gives you the same opaque token in both collections.
{
"collection": "users",
"fields": {
"email": { "technique": "hash" },
"firstName": { "technique": "fake" },
"lastName": { "technique": "fake" },
"phone": { "technique": "partial", "keepFirst": 0, "keepLast": 4 },
"ssn": { "technique": "truncate" },
"password": { "technique": "truncate" }
}
}
Same policy applied to orders.customerEmail:
{
"collection": "orders",
"fields": {
"customerEmail": { "technique": "hash" }
}
}
Result: an analyst can still JOIN users u ON u.email = o.customerEmail in the warehouse, but neither table contains a real address.
GDPR requires stronger handling for EU customers. Apply fake masking only when a document's country field is anything other than the US — US records ship as-is for the US analytics team.
{
"collection": "customers",
"fields": {
"email": {
"technique": "hash",
"when": { "country": { "$ne": "US" } }
},
"firstName": {
"technique": "fake",
"when": { "country": { "$ne": "US" } }
},
"lastName": {
"technique": "fake",
"when": { "country": { "$ne": "US" } }
},
"address": {
"technique": "redact",
"when": { "country": { "$ne": "US" } }
}
}
}
The when clause accepts standard MongoDB match expressions, so you can layer arbitrary conditions (data classification tags, environment, role, etc.).
Apply masking through the field transformation editor. Select a field, open the transformation panel, and choose or write your masking logic.
Partially mask emails to hide the full address while preserving format recognition.
Reveal only the last 4 digits for phone numbers and SSNs - enough for identification, safe for compliance.
Standard PCI-compliant masking showing only the last 4 digits.
Generate fake but realistic names, or redact addresses while keeping city/state for geographic analysis.
Common PII fields and recommended masking strategies.
| Field Type | Sensitivity | Recommended Technique | Example Output |
|---|---|---|---|
| High | partial or hash |
j***@e***.com |
|
| Phone | High | partial (last 4) |
***-***-1234 |
| SSN | Critical | partial (last 4) or hash |
***-**-6789 |
| Credit Card | Critical | partial (last 4) |
****-****-****-1234 |
| Name | Medium | fake |
Jane Wilson |
| Address | Medium | fake or redact |
******** or fake address |
| Birthdate | Medium | randomize or partial (year only) |
1990-01-01 or randomized date |
| IP Address | Medium | randomize or hash |
203.0.113.42 |
| Password | Critical | truncate (drop field) |
(field removed) |
| API Keys | Critical | truncate (drop field) |
(field removed) |
For data that needs referential integrity — user IDs or emails that appear in multiple collections, foreign keys, tenant IDs — use the hash technique. Because SHA-256 is deterministic, the same input always produces the same masked output. A join that worked in production still works after export.
Example: users.email and orders.customerEmail both hash to the same 64-character token, so the analytics warehouse can still join the two tables without ever seeing a real address.
Every field policy accepts an optional when clause, which is evaluated as a MongoDB match expression against the document being exported. Use it to:
{ "country": { "$ne": "US" } }{ "role": { "$ne": "admin" } }{ "classification": "restricted" }{ "$and": [{ "country": "DE" }, { "isMinor": true }] }For highly sensitive fields like passwords and API keys, exclude them entirely rather than masking.
crypto.sha256() for deterministic masking.Download and start managing your MongoDB databases with ease.
Download Free Trial