Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to pretty print all documents from the 'users' collection.
MongoDB
db.users.find().[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'toArray()' instead of 'pretty()' which returns an array but does not format output.
Using 'count()' which returns the number of documents, not the documents themselves.
✗ Incorrect
The 'pretty()' method formats the output for easier reading in the MongoDB shell.
2fill in blank
mediumComplete the code to get the first 5 documents from the 'orders' collection.
MongoDB
db.orders.find().[1](5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'skip()' which skips documents but does not limit the number returned.
Using 'count()' which returns the number of documents, not the documents themselves.
✗ Incorrect
The 'limit()' method restricts the number of documents returned by the query.
3fill in blank
hardFix the error in the code to convert the cursor to an array.
MongoDB
const docs = db.products.find().[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pretty()' which formats output but does not convert to array.
Using 'count()' which returns the number of documents.
✗ Incorrect
The 'toArray()' method converts the cursor to an array of documents.
4fill in blank
hardFill both blanks to skip the first 3 documents and limit the result to 4 documents.
MongoDB
db.sales.find().[1](3).[2](4)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order of 'skip' and 'limit' which changes the result.
Using 'pretty' or 'count' which do not control skipping or limiting.
✗ Incorrect
The 'skip()' method skips documents, and 'limit()' restricts the number returned.
5fill in blank
hardFill all three blanks to pretty print documents from 'inventory', skip 2, and limit to 3.
MongoDB
db.inventory.find().[1]().[2](2).[3](3)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'count()' which does not affect output formatting or cursor behavior.
Changing the order of methods which affects the result.
✗ Incorrect
Use 'pretty()' to format output, 'skip()' to skip documents, and 'limit()' to restrict the number returned.