Below is the bulkWrite
method where I am inserting 1000 docs. The issue is I could not able to extract total upsertedCount
from the results.
what I get those are individual BulkWriteResult
like below for each inserted document
`console.log(results) :->
BulkWriteResult {
insertedCount: 0,
matchedCount: 0,
modifiedCount: 0,
deletedCount: 0,
upsertedCount: 1,
upsertedIds: { '0': new ObjectId('6684fe4d1625ae49f6233577') },
insertedIds: {}
}
`
I will appreciate if someone come up with the solution.
method->
`db.collections.bulkWrite([
{updateMany :
{
"filter": {"name": product.name},
"update": {"$setOnInsert" : {
name: product.name,
description: product.description,
price: product.price,
category: product.category,
}},
upsert: true
}
}
],{ ordered: false } )
.then(results => {
console.log(results)
})
.catch(err=>Error(err))`
I searched in mongodb
docs where I could not found any solution in their docs about how to extract total upsertedCount
.