0
0
MongoDBquery~10 mins

Why managed databases matter 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 connect to a MongoDB database using the correct method.

MongoDB
const client = new MongoClient([1]);
Drag options to blanks, or click blank then click option'
A"mongodb://localhost:27017"
B"localhost:27017"
C"ftp://localhost:27017"
D"http://localhost:27017"
Attempts:
3 left
💡 Hint
Common Mistakes
Using HTTP or FTP protocols instead of MongoDB protocol.
Omitting the protocol prefix entirely.
2fill in blank
medium

Complete the code to select the database named 'shopDB'.

MongoDB
const db = client.[1]('shopDB');
Drag options to blanks, or click blank then click option'
Adatabase
Bdb
CuseDatabase
DgetDatabase
Attempts:
3 left
💡 Hint
Common Mistakes
Using useDatabase which is not a method in the driver.
Using database which is not a method in the driver.
3fill in blank
hard

Fix the error in the code to insert a document into the 'products' collection.

MongoDB
await db.collection('products').[1]({ name: 'Pen', price: 1.5 });
Drag options to blanks, or click blank then click option'
AaddDocument
BinsertMany
Cinsert
DinsertOne
Attempts:
3 left
💡 Hint
Common Mistakes
Using insertMany when inserting a single document.
Using non-existent methods like addDocument or insert.
4fill in blank
hard

Fill both blanks to find all documents in the 'orders' collection where the status is 'pending'.

MongoDB
const pendingOrders = await db.collection('orders').[1]([2]);
Drag options to blanks, or click blank then click option'
Afind
BfindOne
C{ status: 'pending' }
D{ status: 'complete' }
Attempts:
3 left
💡 Hint
Common Mistakes
Using findOne which returns only one document.
Using the wrong filter object.
5fill in blank
hard

Fill all three blanks to update the price of the product named 'Notebook' to 3.0.

MongoDB
await db.collection([1]).updateOne([2], { [3]: { price: 3.0 } });
Drag options to blanks, or click blank then click option'
A'products'
B{ name: 'Notebook' }
C$set
D'orders'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong collection name.
Using an incorrect filter object.
Forgetting to use the update operator like $set.