fixed mongo update for mongo4 #916

This commit is contained in:
SPRINX0\prochazka
2024-10-15 10:38:44 +02:00
parent e54cffbaf3
commit 42601ff960
2 changed files with 21 additions and 17 deletions

View File

@@ -361,16 +361,17 @@ const driver = {
res.replaced.push(resdoc._id);
}
} else {
const resdoc = await collection.updateOne(convertObjectId(update.condition), {
$set: convertObjectId(_.pickBy(update.fields, (v, k) => !v?.$$undefined$$)),
$unset: _.fromPairs(
Object.keys(update.fields)
.filter((k) => update.fields[k]?.$$undefined$$)
.map((k) => [k, ''])
),
const set = convertObjectId(_.pickBy(update.fields, (v, k) => !v?.$$undefined$$));
const unset = _.fromPairs(
Object.keys(update.fields)
.filter((k) => update.fields[k]?.$$undefined$$)
.map((k) => [k, ''])
);
const updates = {};
if (!_.isEmpty(set)) updates.$set = set;
if (!_.isEmpty(unset)) updates.$unset = unset;
// $set: convertObjectId(update.fields),
});
const resdoc = await collection.updateOne(convertObjectId(update.condition), updates);
res.updated.push(resdoc._id);
}
}