From 3f6299805262bfa16e94685e006e2c41eb7b6027 Mon Sep 17 00:00:00 2001 From: Andrey Platov <87076238+aplatoff@users.noreply.github.com> Date: Mon, 29 Nov 2021 12:07:49 +0100 Subject: [PATCH] Make mongo working again (#405) Signed-off-by: Andrey Platov Co-authored-by: Denis Bykhov --- server/mongo/src/storage.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/server/mongo/src/storage.ts b/server/mongo/src/storage.ts index e3fbae62b1..312def10f9 100644 --- a/server/mongo/src/storage.ts +++ b/server/mongo/src/storage.ts @@ -151,11 +151,6 @@ class MongoAdapter extends MongoAdapterBase { protected override async txUpdateDoc (tx: TxUpdateDoc): Promise { const domain = this.hierarchy.getDomain(tx.objectClass) - const operations = { - ...tx.operations, - modifiedBy: tx.modifiedBy, - modifiedOn: tx.modifiedOn - } if (isOperator(tx.operations)) { const operator = Object.keys(tx.operations)[0] if (operator === '$move') { @@ -195,18 +190,30 @@ class MongoAdapter extends MongoAdapterBase { return await this.db.collection(domain).bulkWrite(ops as any) } else { if (tx.retrieve === true) { - const result = await this.db.collection(domain).findOneAndUpdate({ _id: tx.objectId }, operations, { returnDocument: 'after' }) + const result = await this.db.collection(domain).findOneAndUpdate({ _id: tx.objectId }, { + ...tx.operations, + $set: { + modifiedBy: tx.modifiedBy, + modifiedOn: tx.modifiedOn + } + }, { returnDocument: 'after' }) return { object: result.value } } else { - return await this.db.collection(domain).updateOne({ _id: tx.objectId }, operations) + return await this.db.collection(domain).updateOne({ _id: tx.objectId }, { + ...tx.operations, + $set: { + modifiedBy: tx.modifiedBy, + modifiedOn: tx.modifiedOn + } + }) } } } else { if (tx.retrieve === true) { - const result = await this.db.collection(domain).findOneAndUpdate({ _id: tx.objectId }, { $set: operations }, { returnDocument: 'after' }) + const result = await this.db.collection(domain).findOneAndUpdate({ _id: tx.objectId }, { $set: { ...tx.operations, modifiedBy: tx.modifiedBy, modifiedOn: tx.modifiedOn } }, { returnDocument: 'after' }) return { object: result.value } } else { - return await this.db.collection(domain).updateOne({ _id: tx.objectId }, { $set: operations }) + return await this.db.collection(domain).updateOne({ _id: tx.objectId }, { $set: { ...tx.operations, modifiedBy: tx.modifiedBy, modifiedOn: tx.modifiedOn } }) } } }