diff --git a/packages/tools/src/DatabaseAnalyser.ts b/packages/tools/src/DatabaseAnalyser.ts index f113f7a4..f522b0b7 100644 --- a/packages/tools/src/DatabaseAnalyser.ts +++ b/packages/tools/src/DatabaseAnalyser.ts @@ -236,9 +236,9 @@ export class DatabaseAnalyser { this.pool.feedback(obj); } if (obj && obj.analysingMessage) { - logger.debug(obj.analysingMessage); + logger.debug(obj.analysingMessage); } - } + } async getModifications() { const snapshot = await this._getFastSnapshot(); diff --git a/plugins/dbgate-plugin-mongo/src/backend/driver.js b/plugins/dbgate-plugin-mongo/src/backend/driver.js index 93ab9422..9fb20f8c 100644 --- a/plugins/dbgate-plugin-mongo/src/backend/driver.js +++ b/plugins/dbgate-plugin-mongo/src/backend/driver.js @@ -23,7 +23,9 @@ async function readCursor(cursor, options) { function convertObjectId(condition) { return _.cloneDeepWith(condition, (x) => { - if (x && x.$oid) return ObjectId(x.$oid); + if (x && x.$oid) { + return ObjectId.createFromHexString(x.$oid); + } }); } @@ -60,7 +62,9 @@ const driver = { mongoUrl = databaseUrl; } } else { - mongoUrl = user ? `mongodb://${encodeURIComponent(user)}:${encodeURIComponent(password)}@${server}:${port}` : `mongodb://${server}:${port}`; + mongoUrl = user + ? `mongodb://${encodeURIComponent(user)}:${encodeURIComponent(password)}@${server}:${port}` + : `mongodb://${server}:${port}`; } const options = { @@ -93,7 +97,7 @@ const driver = { let func; func = eval(`(db,ObjectId) => ${sql}`); const db = await getScriptableDb(pool); - const res = func(db, ObjectId); + const res = func(db, ObjectId.createFromHexString); if (isPromise(res)) await res; }, async stream(pool, sql, options) { @@ -113,7 +117,7 @@ const driver = { let exprValue; try { - exprValue = func(db, ObjectId); + exprValue = func(db, ObjectId.createFromHexString); } catch (err) { options.info({ message: 'Error evaluating expression: ' + err.message, @@ -227,7 +231,7 @@ const driver = { func = eval(`(db,ObjectId) => ${sql}`); const db = await getScriptableDb(pool); - exprValue = func(db, ObjectId); + exprValue = func(db, ObjectId.createFromHexString); // return directly stream without header row return exprValue.stream(); @@ -290,7 +294,7 @@ const driver = { ...insert.document, ...insert.fields, }; - const resdoc = await collection.insert(convertObjectId(document)); + const resdoc = await collection.insertOne(convertObjectId(document)); res.inserted.push(resdoc._id); } for (const update of changeSet.updates) { diff --git a/plugins/dbgate-plugin-mongo/src/frontend/driver.js b/plugins/dbgate-plugin-mongo/src/frontend/driver.js index 93105563..4ad54613 100644 --- a/plugins/dbgate-plugin-mongo/src/frontend/driver.js +++ b/plugins/dbgate-plugin-mongo/src/frontend/driver.js @@ -67,7 +67,7 @@ const driver = { getCollectionUpdateScript(changeSet) { let res = ''; for (const insert of changeSet.inserts) { - res += `db.${insert.pureName}.insert(${jsonStringifyWithObjectId({ + res += `db.${insert.pureName}.insertOne(${jsonStringifyWithObjectId({ ...insert.document, ...insert.fields, })});\n`;