0
0
MongoDBquery~10 mins

insertMany method 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 insert multiple documents into the collection.

MongoDB
db.collection.insertMany([1])
Drag options to blanks, or click blank then click option'
A[{ name: 'Alice' }, { name: 'Bob' }]
B{ names: ['Alice', 'Bob'] }
C['Alice', 'Bob']
D{ name: 'Alice' }
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single object instead of an array.
Passing an array of strings instead of objects.
2fill in blank
medium

Complete the code to insert multiple documents and handle the promise.

MongoDB
db.collection.insertMany([{ name: 'Eve' }, { name: 'Frank' }]).[1](result => console.log(result.insertedCount))
Drag options to blanks, or click blank then click option'
Acatch
Bawait
Cfinally
Dthen
Attempts:
3 left
💡 Hint
Common Mistakes
Using catch instead of then for success.
Trying to use await without async function.
3fill in blank
hard

Fix the error in the code to correctly insert multiple documents.

MongoDB
db.collection.insertMany([1])
Drag options to blanks, or click blank then click option'
A[{ name: 'Grace' }, { name: 'Heidi' }]
B'Grace', 'Heidi'
C{ name: 'Grace' }
Dname: 'Grace', name: 'Heidi'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single object instead of an array.
Passing a string or invalid syntax.
4fill in blank
hard

Fill both blanks to insert documents and log the inserted IDs.

MongoDB
db.collection.insertMany([1]).[2](result => console.log(result.insertedIds))
Drag options to blanks, or click blank then click option'
A[{ age: 25 }, { age: 30 }]
Bthen
Ccatch
D[{ age: 25 }, { age: 30, city: 'NY' }]
Attempts:
3 left
💡 Hint
Common Mistakes
Using catch instead of then for success.
Passing a single object instead of an array.
5fill in blank
hard

Fill all three blanks to insert documents, handle errors, and log success.

MongoDB
db.collection.insertMany([1]).[2](result => console.log('Inserted:', result.insertedCount)).[3](error => console.error('Error:', error))
Drag options to blanks, or click blank then click option'
A[{ product: 'Book' }, { product: 'Pen' }]
Bthen
Ccatch
D[{ product: 'Book' }, { product: 'Pen', price: 5 }]
Attempts:
3 left
💡 Hint
Common Mistakes
Not handling errors with catch.
Passing a single object instead of an array.