0
0
MongoDBquery~10 mins

$limit and $skip stages in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to limit the results to 5 documents.

MongoDB
db.collection.aggregate([{ $limit: [1] }])
Drag options to blanks, or click blank then click option'
A5
B1
C0
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 will return no documents.
Using a number larger than the collection size returns all documents.
2fill in blank
medium

Complete the code to skip the first 3 documents in the aggregation.

MongoDB
db.collection.aggregate([{ $skip: [1] }])
Drag options to blanks, or click blank then click option'
A0
B1
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 means no documents are skipped.
Using a number larger than the collection size returns no documents.
3fill in blank
hard

Fix the error in the aggregation pipeline to correctly skip 2 documents.

MongoDB
db.collection.aggregate([{ $skip: [1] }])
Drag options to blanks, or click blank then click option'
A'2'
B2
C-2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers causes type errors.
Negative skip values are invalid.
4fill in blank
hard

Fill both blanks to skip the first 4 documents and then limit the results to 3 documents.

MongoDB
db.collection.aggregate([{ $skip: [1] }, { $limit: [2] }])
Drag options to blanks, or click blank then click option'
A4
B3
C5
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the numbers will change the output.
Using numbers too large may return no documents.
5fill in blank
hard

Fill all three blanks to skip 2 documents, limit to 4 documents, and then skip 1 more document.

MongoDB
db.collection.aggregate([{ $skip: [1] }, { $limit: [2] }, { $skip: [3] }])
Drag options to blanks, or click blank then click option'
A2
B4
C1
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing the order of stages changes the result.
Using wrong numbers can return unexpected documents.