mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 06:46:00 +00:00
mongo condition refactor
This commit is contained in:
@@ -7,6 +7,7 @@ const MongoClient = require('mongodb').MongoClient;
|
||||
const ObjectId = require('mongodb').ObjectId;
|
||||
const AbstractCursor = require('mongodb').AbstractCursor;
|
||||
const createBulkInsertStream = require('./createBulkInsertStream');
|
||||
const { convertToMongoCondition } = require('../frontend/convertToMongoCondition');
|
||||
|
||||
function transformMongoData(row) {
|
||||
return _.cloneDeepWith(row, (x) => {
|
||||
@@ -269,10 +270,13 @@ 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 collection = pool.__getDatabase().collection(options.pureName);
|
||||
if (options.countDocuments) {
|
||||
const count = await collection.countDocuments(convertObjectId(options.condition) || {});
|
||||
const count = await collection.countDocuments(convertObjectId(mongoCondition) || {});
|
||||
return { count };
|
||||
} else if (options.aggregate) {
|
||||
let cursor = await collection.aggregate(convertObjectId(options.aggregate));
|
||||
@@ -280,7 +284,7 @@ const driver = {
|
||||
return { rows: rows.map(transformMongoData) };
|
||||
} else {
|
||||
// console.log('options.condition', JSON.stringify(options.condition, undefined, 2));
|
||||
let cursor = await collection.find(convertObjectId(options.condition) || {});
|
||||
let cursor = await collection.find(convertObjectId(mongoCondition) || {});
|
||||
if (options.sort) cursor = cursor.sort(options.sort);
|
||||
if (options.skip) cursor = cursor.skip(options.skip);
|
||||
if (options.limit) cursor = cursor.limit(options.limit);
|
||||
|
||||
Reference in New Issue
Block a user