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:
Choose the appropriate masking strategy based on your data type and use case.
| Mask Type | Description | Input | Output |
|---|---|---|---|
| Redact | Replace with fixed placeholder | john@email.com |
[REDACTED] |
| Partial Mask | Show first/last characters only | john@email.com |
j***@***.com |
| Hash | One-way hash (SHA-256) | john@email.com |
a8f5f167f44f... |
| Tokenize | Replace with consistent token | john@email.com |
USER_8472 |
| Randomize | Replace with random value of same format | 555-123-4567 |
555-847-2918 |
| Fake | Generate realistic fake data | John Smith |
Jane Wilson |
| Null | Replace with null/empty | secret123 |
null |
| Truncate | Keep only first N characters | 1234-5678-9012-3456 |
1234-XXXX-XXXX-XXXX |
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 Mask | Example Output |
|---|---|---|---|
| High | Partial or Hash | j***@***.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 or Initials | J. S. or fake name |
| Address | Medium | Generalize or Redact | [REDACTED], City, ST |
| Birthdate | Medium | Year only or Age bracket | 1990-01-01 or 30-39 |
| IP Address | Medium | Truncate or Randomize | 192.168.XXX.XXX |
| Password | Critical | Null or Exclude | Don't export |
| API Keys | Critical | Null or Exclude | Don't export |
For data that needs referential integrity (e.g., user IDs that appear in multiple collections), use hash-based masking. The same input always produces the same output, preserving relationships across exports.
Apply masking based on document properties - mask only EU users for GDPR, skip admin accounts, or apply different rules per data classification.
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