I'm on mongo v4.2. See the below mongo shell script which is an exact copy of the example from mongo bulkWrite related documentation
db.pizzas.insertMany( [
{ _id: 0, type: "pepperoni", size: "small", price: 4 },
{ _id: 1, type: "cheese", size: "medium", price: 7 },
{ _id: 2, type: "vegan", size: "large", price: 8 }
] )
try {
db.pizzas.bulkWrite( [
{ insertOne: { document: { _id: 3, type: "beef", size: "medium", price: 6 } } },
{ insertOne: { document: { _id: 4, type: "sausage", size: "large", price: 10 } } },
{ updateOne: {
filter: { type: "cheese" },
update: { $set: { price: 8 } }
} },
{ deleteOne: { filter: { type: "pepperoni"} } },
{ replaceOne: {
filter: { type: "vegan" },
replacement: { type: "tofu", size: "small", price: 4 }
} }
] )
} catch( error ) {
print( error )
}
The actual bulkWrite result returned is as follows
{
"acknowledged" : true,
"deletedCount" : 1.0,
"insertedCount" : 2.0,
"matchedCount" : 2.0,
"upsertedCount" : 0.0,
"insertedIds" : {
"0" : 3.0,
"1" : 4.0
},
"upsertedIds" : {
}
}
You will note that the modifiedCount field mentioned in the documentation is missing. Why is it not included? Is matchedCount an alternative?
I also tried another much simpler script to reproduce this
db.someCollection.insertOne({ "_id": 1, "field": "some-value" })
var result = db.someCollection.bulkWrite([{
updateOne: {
filter: { "_id": 1 },
update: { "$set": { "field": "another-value" } },
upsert: false
}
}])
printjson(result)
I see the same behavior. No modifiedCount.
{
"acknowledged" : true,
"deletedCount" : 0.0,
"insertedCount" : 0.0,
"matchedCount" : 1.0,
"upsertedCount" : 0.0,
"insertedIds" : {
},
"upsertedIds" : {
}
}