mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
mongo filtering via sql tree
This commit is contained in:
@@ -270,10 +270,11 @@ const driver = {
|
||||
return res.databases;
|
||||
},
|
||||
async readCollection(pool, options) {
|
||||
const mongoCondition = convertToMongoCondition(options.condition);
|
||||
console.log('******************* mongoCondition *****************')
|
||||
console.log(JSON.stringify(mongoCondition, undefined, 2));
|
||||
try {
|
||||
const mongoCondition = convertToMongoCondition(options.condition);
|
||||
// console.log('******************* mongoCondition *****************');
|
||||
// console.log(JSON.stringify(mongoCondition, undefined, 2));
|
||||
|
||||
const collection = pool.__getDatabase().collection(options.pureName);
|
||||
if (options.countDocuments) {
|
||||
const count = await collection.countDocuments(convertObjectId(mongoCondition) || {});
|
||||
|
||||
@@ -89,6 +89,38 @@ function convertToMongoCondition(filter) {
|
||||
$options: 'i',
|
||||
},
|
||||
};
|
||||
|
||||
case 'specificPredicate':
|
||||
switch (filter.predicate) {
|
||||
case 'exists':
|
||||
return {
|
||||
[convertLeftOperandToMongoColumn(filter.expr)]: {
|
||||
$exists: true,
|
||||
},
|
||||
};
|
||||
case 'notExists':
|
||||
return {
|
||||
[convertLeftOperandToMongoColumn(filter.expr)]: {
|
||||
$exists: false,
|
||||
},
|
||||
};
|
||||
case 'emptyArray':
|
||||
return {
|
||||
[convertLeftOperandToMongoColumn(filter.expr)]: {
|
||||
$exists: true,
|
||||
$eq: [],
|
||||
},
|
||||
};
|
||||
case 'notEmptyArray':
|
||||
return {
|
||||
[convertLeftOperandToMongoColumn(filter.expr)]: {
|
||||
$exists: true,
|
||||
$type: 'array',
|
||||
$ne: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown condition type ${filter.conditionType}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user