Complete the code to start a client session in MongoDB.
const session = client.[1]();In MongoDB, startSession() is the correct method to begin a client session.
Complete the code to start a transaction inside a session.
session.[1]();The correct method to start a transaction in a session is startTransaction().
Fix the error in the code to commit a transaction.
await session.[1]();The correct method to commit a transaction is commitTransaction().
Fill both blanks to abort a transaction and end the session.
await session.[1](); session.[2]();
To abort a transaction, use abortTransaction(). To end the session, use endSession().
Fill all three blanks to run a transaction with a callback function.
await session.withTransaction(async () => {
await collection.[1](doc, { session: [2] });
}, { readPreference: [3] });Inside the transaction callback, use insertOne to add a document. Pass the session object to the operation. Set readPreference to 'primary' for strong consistency.