Complete the code to connect to a MongoDB database using the correct method.
const client = new MongoClient([1]);The connection string for MongoDB starts with mongodb://. This tells the client how to connect to the database.
Complete the code to select the database named 'shopDB'.
const db = client.[1]('shopDB');
useDatabase which is not a method in the driver.database which is not a method in the driver.In MongoDB's Node.js driver, client.db('name') selects the database.
Fix the error in the code to insert a document into the 'products' collection.
await db.collection('products').[1]({ name: 'Pen', price: 1.5 });
insertMany when inserting a single document.addDocument or insert.The correct method to insert a single document is insertOne. Other options are either incorrect or used for multiple documents.
Fill both blanks to find all documents in the 'orders' collection where the status is 'pending'.
const pendingOrders = await db.collection('orders').[1]([2]);
findOne which returns only one document.To get all matching documents, use find with a filter object specifying { status: 'pending' }.
Fill all three blanks to update the price of the product named 'Notebook' to 3.0.
await db.collection([1]).updateOne([2], { [3]: { price: 3.0 } });
We update one document in the 'products' collection where the name is 'Notebook'. The update operator $set changes the price.