mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 13:46:00 +00:00
support remove fields for mongo
This commit is contained in:
@@ -2,6 +2,8 @@ const { driverBase } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||
const { convertToMongoCondition, convertToMongoSort } = require('./convertToMongoCondition');
|
||||
const Dumper = require('./Dumper');
|
||||
const { mongoSplitterOptions } = require('dbgate-query-splitter/lib/options');
|
||||
const _pickBy = require('lodash/pickBy');
|
||||
const _fromPairs = require('lodash/fromPairs');
|
||||
|
||||
function jsonStringifyWithObjectId(obj) {
|
||||
return JSON.stringify(obj, undefined, 2).replace(
|
||||
@@ -96,7 +98,12 @@ const driver = {
|
||||
res += `db.${update.pureName}.updateOne(${jsonStringifyWithObjectId(
|
||||
update.condition
|
||||
)}, ${jsonStringifyWithObjectId({
|
||||
$set: update.fields,
|
||||
$set: _pickBy(update.fields, (v, k) => v !== undefined),
|
||||
$unset: _fromPairs(
|
||||
Object.keys(update.fields)
|
||||
.filter((k) => update.fields[k] === undefined)
|
||||
.map((k) => [k, ''])
|
||||
),
|
||||
})});\n`;
|
||||
}
|
||||
}
|
||||
@@ -140,6 +147,8 @@ const driver = {
|
||||
supportJsonType: true,
|
||||
supportObjectIdType: true,
|
||||
supportNullType: true,
|
||||
|
||||
supportFieldRemoval: true,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user