following answers from here and here, attempting to implement a bulk upsert operation using Mongoose 5.4
Have something like so:
const update = await Company.bulkWrite([
{
'updateOne': {
'filter': { 'url': result.url },
'update': {
testVal: 'testinggg'
},
'upsert': true,
}
},
]);
When I run this, I see the following response:
{
ok: 1,
writeErrors: [ ],
writeConcernErrors: [ ],
insertedIds: [ ],
nInserted: 0,
nUpserted: 0,
nMatched: 1,
nModified: 1,
nRemoved: 0,
upserted: [ ]
}
However, the entry is not actually updated.
If I change the filter so it checks for something and thus needs to create a new entry instead of updating, it works fine. But if the filter property matches and it needs to update, no updates are made to the matching document.
Have also tried using $set but to no avail:
const update = await Company.bulkWrite([
{
'updateOne': {
'filter': { 'url': result.url },
'update': {
'$set': {
testVal: 'testinggg'
}
},
'upsert': true,
}
},
]);
What am I doing wrong here?