From dc31552f9e84a2433555ec58076243ff11b2d94b Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 14 Jul 2022 07:27:38 +0200 Subject: [PATCH] fixed read mongo query #312 --- plugins/dbgate-plugin-mongo/src/backend/driver.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/dbgate-plugin-mongo/src/backend/driver.js b/plugins/dbgate-plugin-mongo/src/backend/driver.js index 2977ff3a..68ea31df 100644 --- a/plugins/dbgate-plugin-mongo/src/backend/driver.js +++ b/plugins/dbgate-plugin-mongo/src/backend/driver.js @@ -5,19 +5,17 @@ const driverBase = require('../frontend/driver'); const Analyser = require('./Analyser'); const MongoClient = require('mongodb').MongoClient; const ObjectId = require('mongodb').ObjectId; -const Cursor = require('mongodb').Cursor; +const AbstractCursor = require('mongodb').AbstractCursor; const createBulkInsertStream = require('./createBulkInsertStream'); function transformMongoData(row) { return _.mapValues(row, (v) => (v && v.constructor == ObjectId ? { $oid: v.toString() } : v)); } -function readCursor(cursor, options) { - return new Promise((resolve) => { - options.recordset({ __isDynamicStructure: true }); - - cursor.on('data', (data) => options.row(transformMongoData(data))); - cursor.on('end', () => resolve()); +async function readCursor(cursor, options) { + options.recordset({ __isDynamicStructure: true }); + await cursor.forEach((row) => { + options.row(transformMongoData(row)); }); } @@ -118,7 +116,7 @@ const driver = { return; } - if (exprValue instanceof Cursor) { + if (exprValue instanceof AbstractCursor) { await readCursor(exprValue, options); } else if (isPromise(exprValue)) { try {