mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 02:13:57 +00:00
feat(mongo): fixed data writes after mongo driver upgrade #798
This commit is contained in:
@@ -236,7 +236,7 @@ export class DatabaseAnalyser {
|
|||||||
this.pool.feedback(obj);
|
this.pool.feedback(obj);
|
||||||
}
|
}
|
||||||
if (obj && obj.analysingMessage) {
|
if (obj && obj.analysingMessage) {
|
||||||
logger.debug(obj.analysingMessage);
|
logger.debug(obj.analysingMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ async function readCursor(cursor, options) {
|
|||||||
|
|
||||||
function convertObjectId(condition) {
|
function convertObjectId(condition) {
|
||||||
return _.cloneDeepWith(condition, (x) => {
|
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;
|
mongoUrl = databaseUrl;
|
||||||
}
|
}
|
||||||
} else {
|
} 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 = {
|
const options = {
|
||||||
@@ -93,7 +97,7 @@ const driver = {
|
|||||||
let func;
|
let func;
|
||||||
func = eval(`(db,ObjectId) => ${sql}`);
|
func = eval(`(db,ObjectId) => ${sql}`);
|
||||||
const db = await getScriptableDb(pool);
|
const db = await getScriptableDb(pool);
|
||||||
const res = func(db, ObjectId);
|
const res = func(db, ObjectId.createFromHexString);
|
||||||
if (isPromise(res)) await res;
|
if (isPromise(res)) await res;
|
||||||
},
|
},
|
||||||
async stream(pool, sql, options) {
|
async stream(pool, sql, options) {
|
||||||
@@ -113,7 +117,7 @@ const driver = {
|
|||||||
|
|
||||||
let exprValue;
|
let exprValue;
|
||||||
try {
|
try {
|
||||||
exprValue = func(db, ObjectId);
|
exprValue = func(db, ObjectId.createFromHexString);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
options.info({
|
options.info({
|
||||||
message: 'Error evaluating expression: ' + err.message,
|
message: 'Error evaluating expression: ' + err.message,
|
||||||
@@ -227,7 +231,7 @@ const driver = {
|
|||||||
|
|
||||||
func = eval(`(db,ObjectId) => ${sql}`);
|
func = eval(`(db,ObjectId) => ${sql}`);
|
||||||
const db = await getScriptableDb(pool);
|
const db = await getScriptableDb(pool);
|
||||||
exprValue = func(db, ObjectId);
|
exprValue = func(db, ObjectId.createFromHexString);
|
||||||
|
|
||||||
// return directly stream without header row
|
// return directly stream without header row
|
||||||
return exprValue.stream();
|
return exprValue.stream();
|
||||||
@@ -290,7 +294,7 @@ const driver = {
|
|||||||
...insert.document,
|
...insert.document,
|
||||||
...insert.fields,
|
...insert.fields,
|
||||||
};
|
};
|
||||||
const resdoc = await collection.insert(convertObjectId(document));
|
const resdoc = await collection.insertOne(convertObjectId(document));
|
||||||
res.inserted.push(resdoc._id);
|
res.inserted.push(resdoc._id);
|
||||||
}
|
}
|
||||||
for (const update of changeSet.updates) {
|
for (const update of changeSet.updates) {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ const driver = {
|
|||||||
getCollectionUpdateScript(changeSet) {
|
getCollectionUpdateScript(changeSet) {
|
||||||
let res = '';
|
let res = '';
|
||||||
for (const insert of changeSet.inserts) {
|
for (const insert of changeSet.inserts) {
|
||||||
res += `db.${insert.pureName}.insert(${jsonStringifyWithObjectId({
|
res += `db.${insert.pureName}.insertOne(${jsonStringifyWithObjectId({
|
||||||
...insert.document,
|
...insert.document,
|
||||||
...insert.fields,
|
...insert.fields,
|
||||||
})});\n`;
|
})});\n`;
|
||||||
|
|||||||
Reference in New Issue
Block a user