0
0
MongoDBquery~10 mins

Why document databases over relational in MongoDB - Test Your Understanding

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

Complete the code to find all documents in the collection.

MongoDB
db.collection.[1]()
Drag options to blanks, or click blank then click option'
Afind
Binsert
Cupdate
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using insert() instead of find() to retrieve data.
Using update() or delete() which modify data, not retrieve.
2fill in blank
medium

Complete the code to insert a new document into the collection.

MongoDB
db.collection.[1]({ name: 'Alice', age: 30 })
Drag options to blanks, or click blank then click option'
Afind
BdeleteOne
CinsertOne
DupdateOne
Attempts:
3 left
💡 Hint
Common Mistakes
Using find() which only retrieves data.
Using deleteOne() or updateOne() which modify or remove data.
3fill in blank
hard

Fix the error in the query to find documents where age is greater than 25.

MongoDB
db.collection.find({ age: { [1]: 25 } })
Drag options to blanks, or click blank then click option'
A$gt
B$lt
C$eq
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt which means less than.
Using $eq which means equal to.
Using $ne which means not equal.
4fill in blank
hard

Fill both blanks to update the age of a user named 'Bob' to 35.

MongoDB
db.collection.updateOne({ name: 'Bob' }, { [1]: { age: [2] } })
Drag options to blanks, or click blank then click option'
A$set
B$inc
C35
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Using $inc which increments a value instead of setting it.
Using the wrong age value.
Omitting the update operator.
5fill in blank
hard

Fill both blanks to delete all documents where age is less than 20.

MongoDB
db.collection.deleteMany({ age: { [1]: [2] } })
Drag options to blanks, or click blank then click option'
A$lt
B20
C$gt
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt which means greater than.
Using the wrong number for age.
Using deleteOne() which deletes only one document.