Mafiree logo
  • About
  • Services
  • Blogs
  • Careers
  • Products
    • orbit logo Orbit
    • streamer logo Xstreami
  • Contact
Schedule a Call
Menu
  • About
  • Services
  • Blogs
  • Careers
  • Products
    • orbit logo Orbit
    • streamer logo Xstreami
  • Contact
  • Schedule a Call
Database
Database Database Managed Services
MySQL MySQL
MySQL Consulting Services
MySQL Migration Services
MySQL Optimization & Query Tuning
MySQL Database Administration
MySQL Backup & Recovery
MySQL Security & Maintenance
MySQL Cloud Services (AWS RDS, Aurora, Google Cloud SQL, Azure)
MySQL for Ecommerce
MySQL High Availability & Replication
MongoDB MongoDB
MongoDB Consulting Services
MongoDB Migration Services
MongoDB Optimization & Query Tuning
MongoDB Database Administration
MongoDB Backup & Recovery
MongoDB Security & Maintenance
MongoDB Cloud (Atlas)
MongoDB Solutions by Industry
MongoDB High Availability & Replication
PostgreSQL PostgreSQL
PostgreSQL Consulting
PostgreSQL Migration & Upgrades
Performance Tuning & Query Optimization
PostgreSQL Administration & Managed Services
High Availability, Clustering & Replication
PostgreSQL Backup, Recovery & Disaster Planning
PostgreSQL Security, Compliance & Auditing
PostgreSQL for Analytics & Data Warehousing
PostgreSQL on Cloud & Containers
PostgreSQL Extensions & Open-Source Integrations
PostgreSQL for Every Industry
SQL Server MSSQL
MSSQL Consulting Services
MSSQL Migration Services
MSSQL Optimization & Query Tuning Services
MSSQL Database Administration Services
MSSQL Backup & Recovery Services
MSSQL High Availability & Replication Services
MSSQL Security & Compliance Services
MSSQL Performance Monitoring & Health Checks
MSSQL Solutions by Industry
Aerospike Aerospike
Aerospike Consulting Services
Aerospike Migration Services
Aerospike Performance Optimization & Tuning
Aerospike Database Administration
Aerospike Backup & Recovery
Aerospike High Availability
Aerospike Cloud & Hybrid Deployments
Aerospike for Real-Time Applications (AdTech, FinTech, Retail, IoT)
Analytics DB
Analytics DB Analytics DB Services
Clickhouse Clickhouse
ClickHouse Consulting Services
ClickHouse Migration Services
ClickHouse Optimization & Query Tuning
ClickHouse Database Administration
ClickHouse Backup & Recovery
ClickHouse Security & Maintenance
ClickHouse Cloud Services (ClickHouse Cloud, AWS, GCP, Azure)
ClickHouse Solutions by Industry
ClickHouse High Availability & Replication
TiDB TiDB
TiDB Consulting & Architecture Planning
TiDB Administration & Maintenance
TiDB Security and Privacy Maintenance
TiDB Performance & Query Optimization
TiDB Migration Services
TiDB Backup & Disaster Recovery
TiDB High Availability Solutions
TiDB Solutions by Industry
TiDB Cloud Services
ScyllaDB ScyllaDB
ScyllaDB Consulting & Architecture Planning
ScyllaDB Administration & Maintenance
ScyllaDB Security and Privacy Maintenance
ScyllaDB Performance & Query Optimization
ScyllaDB Migration Services
ScyllaDB Backup & Disaster Recovery
ScyllaDB High Availability Solutions
ScyllaDB Solutions by Industry
ScyllaDB Cloud Services
DevOps
DevOps DevOps Services
Version Control Version Control
Kubernetes Kubernetes
Infrastructure Infrastructure Management
Web Servers Web Servers
Networking
Networking Networking Services
Basic Basic
Advanced Advanced
MySQL MySQL
MongoDB MongoDB
PostgreSQL PostgreSQL
MSSQL MSSQL
Aerospike Aerospike
Clickhouse Clickhouse
TiDB TiDB
ScyllaDB ScyllaDB
Version Control Version Control
Kubernetes Kubernetes
Infrastructure Infrastructure Management
Web Servers Web Servers
Basic Basic
Advanced Advanced
MySQL Consulting Services
MySQL Migration Services
MySQL Optimization & Query Tuning
MySQL Database Administration
MySQL Backup & Recovery
MySQL Security & Maintenance
MySQL Cloud Services (AWS RDS, Aurora, Google Cloud SQL, Azure)
MySQL for Ecommerce
MySQL High Availability & Replication
MongoDB Consulting Services
MongoDB Migration Services
MongoDB Optimization & Query Tuning
MongoDB Database Administration
MongoDB Backup & Recovery
MongoDB Security & Maintenance
MongoDB Cloud (Atlas)
MongoDB Solutions by Industry
MongoDB High Availability & Replication
PostgreSQL Consulting
PostgreSQL Migration & Upgrades
Performance Tuning & Query Optimization
PostgreSQL Administration & Managed Services
High Availability, Clustering & Replication
PostgreSQL Backup, Recovery & Disaster Planning
PostgreSQL Security, Compliance & Auditing
PostgreSQL for Analytics & Data Warehousing
PostgreSQL on Cloud & Containers
PostgreSQL Extensions & Open-Source Integrations
PostgreSQL for Every Industry
MSSQL Consulting Services
MSSQL Migration Services
MSSQL Optimization & Query Tuning Services
MSSQL Database Administration Services
MSSQL Backup & Recovery Services
MSSQL High Availability & Replication Services
MSSQL Security & Compliance Services
MSSQL Performance Monitoring & Health Checks
MSSQL Solutions by Industry
Aerospike Consulting Services
Aerospike Migration Services
Aerospike Performance Optimization & Tuning
Aerospike Database Administration
Aerospike Backup & Recovery
Aerospike High Availability
Aerospike Cloud & Hybrid Deployments
Aerospike for Real-Time Applications (AdTech, FinTech, Retail, IoT)
ClickHouse Consulting Services
ClickHouse Migration Services
ClickHouse Optimization & Query Tuning
ClickHouse Database Administration
ClickHouse Backup & Recovery
ClickHouse Security & Maintenance
ClickHouse Cloud Services (ClickHouse Cloud, AWS, GCP, Azure)
ClickHouse Solutions by Industry
ClickHouse High Availability & Replication
TiDB Consulting & Architecture Planning
TiDB Administration & Maintenance
TiDB Security and Privacy Maintenance
TiDB Performance & Query Optimization
TiDB Migration Services
TiDB Backup & Disaster Recovery
TiDB High Availability Solutions
TiDB Solutions by Industry
TiDB Cloud Services
ScyllaDB Consulting & Architecture Planning
ScyllaDB Administration & Maintenance
ScyllaDB Security and Privacy Maintenance
ScyllaDB Performance & Query Optimization
ScyllaDB Migration Services
ScyllaDB Backup & Disaster Recovery
ScyllaDB High Availability Solutions
ScyllaDB Solutions by Industry
ScyllaDB Cloud Services
  1. Home
  2. > Blogs
  3. > MongoDB
  4. > MongoDB Data Masking Made Easy: No More a Challenge

MongoDB Data Masking Made Easy: No More a Challenge

Safeguard sensitive information with MongoDB’s data masking solution. Simplify your data security measures and stay compliant without compromising performance.

Rexcily September 24, 2024

Subscribe for email updates

Our valued client, a leading healthcare provider, handles a large amount of sensitive data, including patient medical records and health information. With stricter data privacy regulations, securing this information is crucial for maintaining trust and compliance. To address this, we suggested using Protecting Sensitive Data: Queryable Encryption in MongoDB link

Challenges:
Yet another client, a leading financial services company, handles a large amount of sensitive data, including customer financial information and transaction records needed to secure their MongoDB database against potential data breaches while ensuring regulatory compliance. However, they were using an older version of MongoDB that doesn’t support queryable encryption. Traditional security measures were insufficient, so a more advanced solution was needed to protect sensitive data from unauthorized access. They required encrypted data that could still be queried securely.

Solution:
To meet the client’s needs, we proposed a data-masked, read-only view in MongoDB. MongoDB’s view functionality allows us to define data categories accessible to clients. By securing these views with role-based access controls (RBAC), only authorized users can view the data.

Implementation:
We identified Personally Identifiable Information (PII) such as social security numbers, card names, secret codes, and transaction details as the primary targets for masking. We designed a data-masked, read-only view to ensure this sensitive information is obfuscated and accessible only to authorized users.

Sample:
For example, we identified card_name, card_num, and card_sec_code as PII data. We mask these fields so they cannot be deciphered.

  1. Rs0 [direct: primary] Bank> db.customers_info.find()
  2. [
  3.   {
  4.     _id: ObjectId('6648829655fef720c5bde3ed'),
  5.     card_name: 'Mr.Rexjo moj',
  6.     card_num: '8765345728934565',
  7.     card_expiry: ISODate('2024-12-13T08:58:42.920Z'),
  8.     card_sec_code: '123',
  9.     card_provider_name: 'Credit MasterCard Gold',
  10.     card_type: 'CREDIT',
  11.     transaction_id: 'ab2ty77836e8713656d9bf2debba8900',
  12.     transaction_date: ISODate('2024-05-13T09:32:07.000Z'),
  13.     transaction_amount: Decimal128('5000.98')
  14.   }
  15. ]

Aggregation part of data masking

  1. var MasksStage1 = {
  2.     //TEXT REPLACEMENT WITH ASTERISK
  3.     'card_sec_code': '***',                    
  4.     //TEXT OBFUSCATION RETAINING LAST NUMBER, eg: '1234567890123456' -> 'XXXXXXXXXXXX3456'
  5.     'card_num': {'$concat': [
  6.                     'XXXXXXXXXXXX',
  7.                     {'$substrCP': ['$card_num', 12, 4]},
  8.                 ]},  
  9.     //TEXT OBFUSCATION RETAINING LAST WORD, eg: 'Mrs. Jane A. Doe' -> 'Mx. Xxx Doe' (needs post-processing in a subsequent pipeline stage)
  10.     'card_name': {'$regexFind': {'input': '$card_name', 'regex': /(\S+)$/}},
  11. };
  12. var MasksStage2 = {
  13.     //PARTIAL TEXT OBFUSCATION RETAINING LAST WORD (post processing from previous regex operation to pick out 'match')
  14.     'card_name': {'$concat': ['Mx. Xxx ', {'$ifNull': ['$card_name.match', 'Anonymous']}]},
  15. };
  16. //FULL PIPELINE 
  17. var pipeline = [
  18.     {'$set': MasksStage1},
  19.     {'$set': MasksStage2},
  20. ];

Create a view with the masked data:

db.createView('customers_info_view', 'customers_info', pipeline);

Output of the masked data

  1. Rs0 [direct: primary] Bank> db.customers_info_view.find()
  2. [
  3.   {
  4.     _id: ObjectId('6648829655fef720c5bde3ed'),
  5.     card_name: 'Mx. Xxx moj',
  6.     card_num: 'XXXXXXXXXXXX4565',
  7.     card_expiry: ISODate('2024-12-13T08:58:42.920Z'),
  8.     card_sec_code: '***',
  9.     card_provider_name: 'Credit MasterCard Gold',
  10.     card_type: 'CREDIT',
  11.     transaction_id: 'ab2ty77836e8713656d9bf2debba8900',
  12.     transaction_date: ISODate('2024-05-13T09:32:07.000Z'),
  13.     transaction_amount: Decimal128('5000.98')
  14.   }
  15. ]

Here you can see card_name,card_num and card_sec_code fields are masked in a way that they cannot be deciphered.

Additional features that can be achieved through the data masking, which will be covered in the upcoming blogs.

  • Data - masked aggregation on demand
  • Data - masked copy of original data
  • Overwriting original data with masked values

Implementing data masking in MongoDB provides our client with a strong security measure to protect sensitive information and maintain regulatory compliance. Using MongoDB’s encryption capabilities, we ensure that customer data is protected from unauthorized access, strengthening trust in our client’s services.

At Mafiree, we are dedicated to delivering customized solutions to meet your specific security needs. For inquiries or assistance with data masking and enhancing data security in MongoDB, please contact us.

Author Bio

Rexcily

Rexcily Rijo is a MongoDB Certified DBA at Mafiree, with deep expertise in MongoDB database administration, performance optimization, and scalable data solutions. He writes practical, hands-on technical content focused on MongoDB internals, best practices for database operations, TTL and index strategies, and real-world techniques that help engineers and DBAs manage and optimize modern document databases.

Leave a Comment

Related Blogs

MongoDB Transactions: A Comprehensive Guide to ACID Compliance

MongoDB ensures data consistency with single-document atomic operations and multi-document transactions. This guide explains how to implement transactions, their limitations, performance impacts, and best practices for production environments. It also highlights when to use distributed transactions and how expert consulting can help optimize performance.

  289 views
Let MongoDB Clean Up After Itself: A Complete Guide to TTL Indexes

Tired of bloated log collections and messy data? TTL indexes in MongoDB automate your cleanup no cron jobs, no scripts. Learn how to set up, monitor, and optimize TTL for cleaner, faster, and self-maintaining databases.

  4933 views
Top 10 MongoDB Operators Every Developer Should Know (With Examples)

Unlock MongoDB’s full potential! Discover the most powerful MongoDB query operators to supercharge your queries with practical examples every developer can use. #MongoDB #DeveloperTips

  2703 views
Reclaiming MongoDB Storage Space: A Journey to 50% Space Reduction

Efficiently Reclaim Disk Space in MongoDB: Strategies and Solutions for Optimal Performance.

  1988 views
Don't Let Hackers In: How to Secure and Harden Your MongoDB Database

Learn how to protect your MongoDB database with robust security practices, including user authentication, encryption, IP whitelisting, and input validation. Ensure your data remains safe and accessible in today's evolving threat landscape.

  3646 views

Subscribe for email updates

Get in touch with us

Highlights

More than 6000 Servers Monitored

Happy Clients

Certified DBAs

24 x 7 x 365 Support

PCI

Database Services

MySQL MongoDB PostgreSQL SQL Server Aerospike Clickhouse TiDB MariaDB Columnstore

Quick Links

Careers Blog Contact Privacy Policy Disclaimer Policy

Contacts

Linkedin Mafiree Facebook Mafiree Twitter Mafiree

Nagercoil Office

Miru IT Park, Vallankumaranvillai,

Nagercoil, Tamilnadu - 629 002.

Bangalore Office

Unit 303, Vanguard Rise,

5th Main, Konena Agrahara,

Old Airport Road, Bangalore - 560 017.

Call: +91 6383016411

Email: sales@mafiree.com


Copyright © - All Rights Reserved - Mafiree