From eaa943a39d005b17b70656cfe096f361aa8dd8ae Mon Sep 17 00:00:00 2001 From: "SPRINX0\\prochazka" Date: Fri, 23 Aug 2024 16:27:36 +0200 Subject: [PATCH] mongo - using ejson --- plugins/dbgate-plugin-mongo/package.json | 11 ++++++----- plugins/dbgate-plugin-mongo/src/backend/driver.js | 15 ++++----------- yarn.lock | 5 +++++ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/plugins/dbgate-plugin-mongo/package.json b/plugins/dbgate-plugin-mongo/package.json index 1a0b8087..3d28ffd5 100644 --- a/plugins/dbgate-plugin-mongo/package.json +++ b/plugins/dbgate-plugin-mongo/package.json @@ -31,14 +31,15 @@ "prepublishOnly": "yarn build" }, "devDependencies": { + "bson": "^6.8.0", "dbgate-plugin-tools": "^1.0.7", "dbgate-query-splitter": "^4.10.1", - "lodash": "^4.17.21", - "webpack": "^5.91.0", - "webpack-cli": "^5.1.4", "dbgate-tools": "^5.0.0-alpha.1", "is-promise": "^4.0.0", + "lodash": "^4.17.21", "mongodb": "^6.3.0", - "mongodb-client-encryption": "^6.0.0" + "mongodb-client-encryption": "^6.0.0", + "webpack": "^5.91.0", + "webpack-cli": "^5.1.4" } -} \ No newline at end of file +} diff --git a/plugins/dbgate-plugin-mongo/src/backend/driver.js b/plugins/dbgate-plugin-mongo/src/backend/driver.js index f7b1aec2..9a91dcca 100644 --- a/plugins/dbgate-plugin-mongo/src/backend/driver.js +++ b/plugins/dbgate-plugin-mongo/src/backend/driver.js @@ -3,9 +3,8 @@ const stream = require('stream'); const isPromise = require('is-promise'); const driverBase = require('../frontend/driver'); const Analyser = require('./Analyser'); -const MongoClient = require('mongodb').MongoClient; -const ObjectId = require('mongodb').ObjectId; -const AbstractCursor = require('mongodb').AbstractCursor; +const { MongoClient, ObjectId, AbstractCursor } = require('mongodb'); +const { EJSON } = require('bson'); const createBulkInsertStream = require('./createBulkInsertStream'); const { convertToMongoCondition, @@ -14,9 +13,7 @@ const { } = require('../frontend/convertToMongoCondition'); function transformMongoData(row) { - return _.cloneDeepWith(row, (x) => { - if (x && x.constructor == ObjectId) return { $oid: x.toString() }; - }); + return EJSON.serialize(row); } async function readCursor(cursor, options) { @@ -27,11 +24,7 @@ async function readCursor(cursor, options) { } function convertObjectId(condition) { - return _.cloneDeepWith(condition, (x) => { - if (x && x.$oid) { - return ObjectId.createFromHexString(x.$oid); - } - }); + return EJSON.deserialize(condition); } function findArrayResult(resValue) { diff --git a/yarn.lock b/yarn.lock index 817e109d..84be0550 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2458,6 +2458,11 @@ bson@^6.7.0: resolved "https://registry.yarnpkg.com/bson/-/bson-6.7.0.tgz#51973b132cdc424c8372fda3cb43e3e3e2ae2227" integrity sha512-w2IquM5mYzYZv6rs3uN2DZTOBe2a0zXLj53TGDqwF4l6Sz/XsISrisXOJihArF9+BZ6Cq/GjVht7Sjfmri7ytQ== +bson@^6.8.0: + version "6.8.0" + resolved "https://registry.yarnpkg.com/bson/-/bson-6.8.0.tgz#5063c41ba2437c2b8ff851b50d9e36cb7aaa7525" + integrity sha512-iOJg8pr7wq2tg/zSlCCHMi3hMm5JTOxLTagf3zxhcenHsFp+c6uOs6K7W5UE7A4QIJGtqh/ZovFNMP4mOPJynQ== + buffer-crc32@^0.2.5: version "0.2.13" resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242"