Exercises
An exercises about find() operation
Exercise 1
Preliminary
Import
people.json
intolab4.people
(i.e. database name islab4
and collection name ispeople
)
Questions
Find the documents whose age under 22.
Find the documents whose age is between 22 and 26 (inclusive).
Find the document whose name is “Lee” suppressing the profile.
Find the documents whose name is not Lee.
Find the documents whose name is “Lee” or “Park”.
Find the documents whose name is not “Kim” or “Park” or “Lee”.
Exercise 2
Preliminary
Import
inventory.json
into lab4.inventory
Questions
Find documents where the tags field contains below elements.
appliance, school, and book.
Hint: recall
$all
operator
Find all documents but select at most three items in the tags field.
Hint: recall
$slice
operator
Find all documents but select items from the second to the fourth in the tags field.
Hint: recall
$slice
operator with[skip, limit]
Find documents that have brown color in the qty field.
Hint: recall
$elemMatch
operator
Exercise 3
Preliminary
Import
store.json
to the store collection
Questions
Find documents where buyer's name is "J.S. Lee"
Hint: Querying embedded document.
Print purchased items where a name in a document is "iPhone Xs"
Hint: Querying embedded document, Projection
Print the buyer’s purchase method where items contain the document that price is more than 2000$
Hint: < array.field >, Projection
Find documents that don’t have carrier as key in attribute where the name is "Apple Watch Series 4"
Hint:
$elemMatch
,$exists
Exercise 4
Preliminary
Import
store.json
to the store collectionSame with Exercise 3!
Questions
Find documents where buyer's name is "J.S. Lee"
Hint: Querying embedded document.
Print purchased items where a name in a document is "iPhone Xs".
Hint: Querying embedded document, Projection
Print the buyer’s purchase method where items contain the document that price is more than 2000$.
Hint:
<array.field>
, Projection
Find documents that don’t have carrier as key in attribute where the name is "Apple Watch Series 4"
Hint:
$elemMatch
,$exists
Exercise 5
Preliminary
Import
store.json
to the store collectionSame with Exercise 3!
Questions
Get the first three documents and print buyers field only.
Skip a document and then print two documents
Count documents in the store collection.
Exercise 6
Preliminary
Using
grade.json
(import it using mongoimport)
Questions
The grade’s document can have among three types:
quiz, exam or homework
Student id (sid) is from 0 to 99
A document is lost, which contains a quiz score 1. print lost document’s sid. 2. Insert the quiz score (80) to the corresponding sid 3. print the three students that have the highest quiz score.
A simple example of the dataset looks like ...
Exercise 7
Preliminary
Using
grade.json
(import it using mongoimport)Same with exercise 6
Questions
Write the score searching script
Search documents by filtering type and score fields
Results
Last updated