Challenge - 5 Problems
MongoDB Database Creator
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this MongoDB command?
Consider the following MongoDB shell command:
What will be the output after running this command?
use myNewDBWhat will be the output after running this command?
MongoDB
use myNewDB
Attempts:
2 left
💡 Hint
The 'use' command switches the current database context.
✗ Incorrect
The 'use' command in MongoDB switches the shell to the specified database. If the database does not exist yet, it will be created when you first store data in it. The shell outputs 'switched to db '.
❓ query_result
intermediate2:00remaining
What happens when you create a collection explicitly?
Given the command:
What is the result of running this command in MongoDB shell?
db.createCollection('users')What is the result of running this command in MongoDB shell?
MongoDB
db.createCollection('users')Attempts:
2 left
💡 Hint
Creating a collection explicitly returns a success status.
✗ Incorrect
The createCollection command returns an object with 'ok' set to 1 on success. If the collection already exists, it throws an error.
📝 Syntax
advanced2:00remaining
Which command correctly creates a capped collection named 'logs'?
You want to create a capped collection named 'logs' with a maximum size of 1MB. Which command is correct?
Attempts:
2 left
💡 Hint
The 'capped' option must be true and 'size' specifies the max bytes.
✗ Incorrect
To create a capped collection, set 'capped' to true and specify 'size' in bytes. 'max' is for max documents, not size. 'maxSize' is not a valid option.
🧠 Conceptual
advanced2:00remaining
Why does MongoDB create a database only after inserting data?
In MongoDB, when you run
use newDB, the database is not created immediately. Why is this behavior designed this way?Attempts:
2 left
💡 Hint
Think about resource usage and efficiency.
✗ Incorrect
MongoDB delays creating a database until data is inserted to avoid creating empty databases and wasting disk space.
🔧 Debug
expert2:00remaining
Identify the error in this collection creation command
What error will this command produce?
Note: size is given as a string.
db.createCollection('events', {capped: true, size: '1000'})Note: size is given as a string.
MongoDB
db.createCollection('events', {capped: true, size: '1000'})
Attempts:
2 left
💡 Hint
Check the data type required for the size option.
✗ Incorrect
The 'size' option must be a number representing bytes. Passing a string causes a MongoServerError indicating the size must be numeric.