legacy mongodb optimalization + test fix

This commit is contained in:
SPRINX0\prochazka
2025-11-21 10:44:06 +01:00
parent 44366f7872
commit a3cfc45fef
2 changed files with 4 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ const volatilePackages = [
'@clickhouse/client', '@clickhouse/client',
'bson', // this package is already bundled and is used in mongodb 'bson', // this package is already bundled and is used in mongodb
'mongodb', 'mongodb',
'mongodb-old',
'mongodb-client-encryption', 'mongodb-client-encryption',
'tedious', 'tedious',
'msnodesqlv8', 'msnodesqlv8',

View File

@@ -5,9 +5,7 @@ const driverBases = require('../frontend/drivers');
const Analyser = require('./Analyser'); const Analyser = require('./Analyser');
const isPromise = require('is-promise'); const isPromise = require('is-promise');
const mongodb = require('mongodb'); const mongodb = require('mongodb');
const oldmongodb = require('mongodb-old');
const { ObjectId } = require('mongodb'); const { ObjectId } = require('mongodb');
// { MongoClient, ObjectId, AbstractCursor, Long }
const { EJSON } = require('bson'); const { EJSON } = require('bson');
const { serializeJsTypesForJsonStringify, deserializeJsTypesFromJsonParse, getLogger } = require('dbgate-tools'); const { serializeJsTypesForJsonStringify, deserializeJsTypesFromJsonParse, getLogger } = require('dbgate-tools');
const createBulkInsertStream = require('./createBulkInsertStream'); const createBulkInsertStream = require('./createBulkInsertStream');
@@ -22,7 +20,7 @@ let isProApp;
const logger = getLogger('mongoDriver'); const logger = getLogger('mongoDriver');
function serializeMongoData(row, driverBase) { function serializeMongoData(row, driverBase) {
const { Long } = driverBase.useLegacyDriver ? oldmongodb : mongodb; const { Long } = driverBase.useLegacyDriver ? require('mongodb-old') : mongodb;
return EJSON.serialize( return EJSON.serialize(
serializeJsTypesForJsonStringify(row, (value) => { serializeJsTypesForJsonStringify(row, (value) => {
if (value instanceof Long) { if (value instanceof Long) {
@@ -124,7 +122,7 @@ const drivers = driverBases.map((driverBase) => ({
options.tlsInsecure = !ssl.rejectUnauthorized; options.tlsInsecure = !ssl.rejectUnauthorized;
} }
const { MongoClient } = driverBase.useLegacyDriver ? oldmongodb : mongodb; const { MongoClient } = driverBase.useLegacyDriver ? require('mongodb-old') : mongodb;
const client = new MongoClient(mongoUrl, options); const client = new MongoClient(mongoUrl, options);
await client.connect(); await client.connect();
@@ -320,7 +318,7 @@ const drivers = driverBases.map((driverBase) => ({
return; return;
} }
const { AbstractCursor } = driverBase.useLegacyDriver ? oldmongodb : mongodb; const { AbstractCursor } = driverBase.useLegacyDriver ? require('mongodb-old') : mongodb;
if (exprValue instanceof AbstractCursor) { if (exprValue instanceof AbstractCursor) {
await readCursor(exprValue, options, driverBase); await readCursor(exprValue, options, driverBase);