Challenge - 5 Problems
Array Insert Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What documents are inserted with this array insert?
Given the following MongoDB insert command, what documents will be stored in the collection?
MongoDB
db.students.insertMany([
{ name: "Alice", scores: [85, 90, 88] },
{ name: "Bob", scores: [78, 82, 80] }
])Attempts:
2 left
💡 Hint
Remember that insertMany inserts each object in the array as a separate document.
✗ Incorrect
The insertMany method inserts each object in the array as a separate document, preserving the array field 'scores' as is.
🧠 Conceptual
intermediate1:30remaining
How does MongoDB handle arrays in inserted documents?
When inserting a document with an array field in MongoDB, how is the array stored?
Attempts:
2 left
💡 Hint
Think about how JSON arrays are represented in MongoDB documents.
✗ Incorrect
MongoDB stores arrays as a single field containing an ordered list of elements, preserving the array structure.
📝 Syntax
advanced2:30remaining
Which insert command correctly inserts multiple documents with array fields?
Choose the correct MongoDB command to insert two documents, each having a 'tags' array field.
Attempts:
2 left
💡 Hint
Check the syntax for insertMany and how arrays are represented.
✗ Incorrect
Option C correctly uses insertMany with an array of documents, each having a 'tags' array field. Other options have syntax errors or wrong array usage.
❓ optimization
advanced3:00remaining
Best practice for inserting many documents with large arrays?
You need to insert 10,000 documents, each with a large array field. What is the best approach to optimize insertion speed in MongoDB?
Attempts:
2 left
💡 Hint
Think about balancing batch size and memory usage.
✗ Incorrect
Batching inserts with insertMany improves performance and avoids memory overload compared to single inserts or one huge batch.
🔧 Debug
expert3:00remaining
Why does this insertMany command fail?
Consider this command:
db.products.insertMany([
{ name: "Pen", colors: "blue", "red" },
{ name: "Pencil", colors: ["yellow", "black"] }
])
Why does it fail?
Attempts:
2 left
💡 Hint
Look carefully at how the 'colors' field is written in the first document.
✗ Incorrect
The first document tries to assign multiple values to 'colors' without using an array (square brackets), causing a syntax error.