Final Question 5

About final question 5:

Assuming we the following code:

const baseballPlayers = [
  { insertOne: { '_id': 11, 'name': 'Edgar Martinez', 'salary': "8.5M" }},    // Insert #1
  { insertOne: { '_id': 3, 'name': 'Alex Rodriguez', 'salary': "18.3M" }},    // Insert #2
  { insertOne: { '_id': 24, 'name': 'Ken Griffey Jr.', 'salary': "12.4M" }},  // Insert #3
  { insertOne: { '_id': 11, 'name': 'David Bell', 'salary': "2.5M" }},        // Insert #4
  { insertOne: { '_id': 19, 'name': 'Jay Buhner', 'salary': "5.1M" }}         // Insert #5
]

const bulkWriteResponse = employees.bulkWrite(baseballPlayers)

Which of the insert operations in requests will succeed?

I tried #1, #2, #3 and #5 but this is not right. Am I missing something here?

The only insert that will not work is #4 because we are using an existing _id. Right?

Hi @Andre_Mendes,

You are right, but we are doing bulkWrite without mentioning ordered option which means it will run with the order of operations, so #4 will throw an error and insertion will stop.

Here is the documentation link.

Kanika

That´s true! Thank you @kanikasingla

1 Like