mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-03 11:43:57 +00:00
fixed mongo update for mongo4 #916
This commit is contained in:
@@ -361,16 +361,17 @@ const driver = {
|
|||||||
res.replaced.push(resdoc._id);
|
res.replaced.push(resdoc._id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const resdoc = await collection.updateOne(convertObjectId(update.condition), {
|
const set = convertObjectId(_.pickBy(update.fields, (v, k) => !v?.$$undefined$$));
|
||||||
$set: convertObjectId(_.pickBy(update.fields, (v, k) => !v?.$$undefined$$)),
|
const unset = _.fromPairs(
|
||||||
$unset: _.fromPairs(
|
|
||||||
Object.keys(update.fields)
|
Object.keys(update.fields)
|
||||||
.filter((k) => update.fields[k]?.$$undefined$$)
|
.filter((k) => update.fields[k]?.$$undefined$$)
|
||||||
.map((k) => [k, ''])
|
.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);
|
res.updated.push(resdoc._id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,16 +95,19 @@ const driver = {
|
|||||||
...update.fields,
|
...update.fields,
|
||||||
})});\n`;
|
})});\n`;
|
||||||
} else {
|
} else {
|
||||||
res += `db.${update.pureName}.updateOne(${jsonStringifyWithObjectId(
|
const set = _pickBy(update.fields, (v, k) => v !== undefined);
|
||||||
update.condition
|
const unset = _fromPairs(
|
||||||
)}, ${jsonStringifyWithObjectId({
|
|
||||||
$set: _pickBy(update.fields, (v, k) => v !== undefined),
|
|
||||||
$unset: _fromPairs(
|
|
||||||
Object.keys(update.fields)
|
Object.keys(update.fields)
|
||||||
.filter((k) => update.fields[k] === undefined)
|
.filter((k) => update.fields[k] === undefined)
|
||||||
.map((k) => [k, ''])
|
.map((k) => [k, ''])
|
||||||
),
|
);
|
||||||
})});\n`;
|
const updates = {};
|
||||||
|
if (!_.isEmpty(set)) updates.$set = set;
|
||||||
|
if (!_.isEmpty(unset)) updates.$unset = unset;
|
||||||
|
|
||||||
|
res += `db.${update.pureName}.updateOne(${jsonStringifyWithObjectId(
|
||||||
|
update.condition
|
||||||
|
)}, ${jsonStringifyWithObjectId(updates)});\n`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const del of changeSet.deletes) {
|
for (const del of changeSet.deletes) {
|
||||||
|
|||||||
Reference in New Issue
Block a user