feat(mongo): fixed data writes after mongo driver upgrade #798

This commit is contained in:
Jan Prochazka 2024-05-24 09:37:44 +02:00
parent 79793d1b58
commit 5fe55af3b7
3 changed files with 13 additions and 9 deletions

View File

@ -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();

View File

@ -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) {

View File

@ -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`;