mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 16:06:01 +00:00
fixed mongo update for mongo4 #916
This commit is contained in:
@@ -95,16 +95,19 @@ const driver = {
|
||||
...update.fields,
|
||||
})});\n`;
|
||||
} else {
|
||||
const set = _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;
|
||||
|
||||
res += `db.${update.pureName}.updateOne(${jsonStringifyWithObjectId(
|
||||
update.condition
|
||||
)}, ${jsonStringifyWithObjectId({
|
||||
$set: _pickBy(update.fields, (v, k) => v !== undefined),
|
||||
$unset: _fromPairs(
|
||||
Object.keys(update.fields)
|
||||
.filter((k) => update.fields[k] === undefined)
|
||||
.map((k) => [k, ''])
|
||||
),
|
||||
})});\n`;
|
||||
)}, ${jsonStringifyWithObjectId(updates)});\n`;
|
||||
}
|
||||
}
|
||||
for (const del of changeSet.deletes) {
|
||||
|
||||
Reference in New Issue
Block a user