📖 Scenario: You are working for a company that stores sensitive customer data in a MongoDB database. To protect this data, you need to set up encryption at rest, which means the data is encrypted when saved on disk.This project will guide you through creating a MongoDB collection, configuring encryption settings, and verifying the encryption setup.
🎯 Goal: Build a MongoDB setup that demonstrates encryption at rest by creating a collection, configuring encryption options, and ensuring data is stored securely.
📋 What You'll Learn
Create a MongoDB collection named customers with sample data
Add a configuration variable for encryption key management
Apply encryption at rest settings using MongoDB's encryption options
Complete the setup by enabling encryption in the MongoDB configuration
💡 Why This Matters
🌍 Real World
Encrypting data at rest protects sensitive information from unauthorized access if storage devices are lost or stolen.
💼 Career
Understanding encryption at rest is essential for database administrators and security engineers to ensure compliance and data protection.
Progress0 / 4 steps
1
Create the customers collection with sample data
Create a MongoDB collection called customers and insert these exact documents: { _id: 1, name: "Alice", email: "alice@example.com" } and { _id: 2, name: "Bob", email: "bob@example.com" }.
MongoDB
Hint
Use db.customers.insertMany() with an array of documents.
2
Add encryption key configuration
Create a variable called encryptionKey and set it to the string "myEncryptionKey123" to represent the encryption key for data at rest.
MongoDB
Hint
Use const encryptionKey = "myEncryptionKey123" to store the key.
3
Apply encryption at rest settings
Use the createCollection command with the option encryptedFields to specify that the email field in the customers collection should be encrypted. Use encryptionKey as the key identifier.
MongoDB
Hint
Use db.createCollection with encryptedFields option specifying the email field and keyId as encryptionKey.
4
Enable encryption in MongoDB configuration
Add a configuration setting called enableEncryptionAtRest and set it to true to enable encryption at rest in the MongoDB setup.
MongoDB
Hint
Set const enableEncryptionAtRest = true to enable encryption.
Practice
(1/5)
1. What does encryption at rest mean in MongoDB?
easy
A. Data is encrypted only in the application memory.
B. Data is encrypted when stored on disk to protect it from unauthorized access.
C. Data is encrypted only during query execution.
D. Data is encrypted only when it is sent over the network.
Solution
Step 1: Understand encryption at rest meaning
Encryption at rest means data is protected by encoding it while stored on disk, not just during transfer or processing.
Step 2: Identify correct option
Only Data is encrypted when stored on disk to protect it from unauthorized access. correctly describes encryption at rest as protecting stored data on disk.
Final Answer:
Data is encrypted when stored on disk to protect it from unauthorized access. -> Option B
Quick Check:
Encryption at rest = Data encrypted on disk [OK]
Hint: Encryption at rest means data is safe on disk, not just in transit [OK]
Common Mistakes:
Confusing encryption at rest with encryption in transit
Thinking encryption happens only during queries
Assuming encryption applies only in memory
2. Which of the following is the correct way to enable encryption at rest in MongoDB?
easy
A. Run a query like db.enableEncryption() in the shell.
B. Use encrypt() command on collections.
C. Configure the MongoDB server with encryption options in the config file.
D. Set encryption flags in the client application code.
Solution
Step 1: Know how encryption at rest is enabled
Encryption at rest is enabled by configuring the MongoDB server settings, not by running queries or client code.
Step 2: Match correct method
Only Configure the MongoDB server with encryption options in the config file. correctly states enabling encryption via server config file.
Final Answer:
Configure the MongoDB server with encryption options in the config file. -> Option C
Quick Check:
Encryption at rest enabled via server config [OK]
Hint: Encryption at rest is a server setting, not a query command [OK]
Common Mistakes:
Trying to enable encryption using shell queries
Assuming client code controls encryption at rest
Confusing encryption at rest with field-level encryption
3. Given MongoDB is configured with encryption at rest enabled, what will happen if the encryption key is lost?
medium
A. Only new data is encrypted; old data remains readable.
B. Data can still be read normally without the key.
C. MongoDB automatically regenerates the key and decrypts data.
D. Data becomes inaccessible and cannot be decrypted.
Solution
Step 1: Understand role of encryption key
The encryption key is essential to decrypt data stored on disk. Losing it means data cannot be read.
Step 2: Evaluate options
Data becomes inaccessible and cannot be decrypted. correctly states data becomes inaccessible without the key. Other options are incorrect because data cannot be read or auto-decrypted without the key.
Final Answer:
Data becomes inaccessible and cannot be decrypted. -> Option D
Quick Check:
Lost key = no data access [OK]
Hint: Without the key, encrypted data is unreadable [OK]
Common Mistakes:
Assuming MongoDB can recover data without the key
Thinking only new data is encrypted
Believing data remains readable without key
4. A MongoDB admin tries to enable encryption at rest by running db.enableEncryption() in the shell but gets an error. What is the likely cause?
medium
A. Encryption at rest cannot be enabled via shell commands; it requires server config changes.
B. The shell command syntax is incorrect; it should be db.enableEncryption(true).
C. Encryption at rest is enabled by default and does not require commands.
D. The admin lacks permissions to run shell commands.
Solution
Step 1: Understand how encryption at rest is enabled
Encryption at rest is a server-level feature enabled via configuration files, not shell commands.
Step 2: Identify cause of error
Trying to enable it via db.enableEncryption() causes error because this command does not exist.
Final Answer:
Encryption at rest cannot be enabled via shell commands; it requires server config changes. -> Option A
Quick Check:
Enable encryption via config, not shell [OK]
Hint: Encryption at rest needs config file, not shell commands [OK]
Common Mistakes:
Trying to enable encryption with shell commands
Assuming encryption is on by default
Blaming permissions instead of wrong method
5. You want to ensure your MongoDB data is encrypted at rest and can be recovered safely. Which combination of steps is best practice?
hard
A. Enable encryption at rest in server config and securely manage encryption keys separately.
B. Encrypt data manually in application code and store keys in the database.
C. Use shell commands to enable encryption and keep keys in the same server folder.
D. Rely on MongoDB default settings without managing keys.
Solution
Step 1: Understand encryption at rest best practices
Encryption at rest should be enabled via server config, and keys must be managed securely outside the database for safety and recovery.
Step 2: Evaluate options for key management and encryption
Enable encryption at rest in server config and securely manage encryption keys separately. correctly combines enabling encryption at rest with secure key management. Other options either misuse shell commands, store keys insecurely, or rely on defaults.
Final Answer:
Enable encryption at rest in server config and securely manage encryption keys separately. -> Option A
Quick Check:
Config encryption + secure keys = best practice [OK]
Hint: Enable encryption in config and keep keys safe separately [OK]
Common Mistakes:
Storing keys inside the database
Trying to enable encryption via shell commands
Ignoring key management importance
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.