fix mongo $inc operator

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-09-28 22:47:17 +02:00
parent 75c90a3d6c
commit a5ccda96c4
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
2 changed files with 13 additions and 2 deletions

View File

@ -78,6 +78,15 @@ const operators: Record<string, _OperatorFunc> = {
$inc $inc
} }
/**
* @public
*/
export function isOperator (o: Record<string, any>): boolean {
if (o === null || typeof o !== 'object') { return false }
const keys = Object.keys(o)
return keys.length > 0 && keys.every((key) => key.startsWith('$'))
}
/** /**
* @internal * @internal
* @param name - * @param name -

View File

@ -13,7 +13,8 @@
// limitations under the License. // limitations under the License.
// //
import core, { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions, TxCreateDoc, TxUpdateDoc, TxMixin, TxPutBag, TxRemoveDoc, TxProcessor, Hierarchy, DOMAIN_TX, SortingOrder } from '@anticrm/core' import type { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions, TxCreateDoc, TxUpdateDoc, TxMixin, TxPutBag, TxRemoveDoc } from '@anticrm/core'
import core, { DOMAIN_TX, SortingOrder, TxProcessor, Hierarchy, isOperator } from '@anticrm/core'
import type { DbAdapter, TxAdapter } from '@anticrm/server-core' import type { DbAdapter, TxAdapter } from '@anticrm/server-core'
@ -114,7 +115,8 @@ class MongoAdapter extends MongoAdapterBase {
protected override async txUpdateDoc (tx: TxUpdateDoc<Doc>): Promise<void> { protected override async txUpdateDoc (tx: TxUpdateDoc<Doc>): Promise<void> {
const domain = this.hierarchy.getDomain(tx.objectClass) const domain = this.hierarchy.getDomain(tx.objectClass)
await this.db.collection(domain).updateOne({ _id: tx.objectId }, { $set: tx.operations }) const op = isOperator(tx.operations) ? tx.operations : { $set: tx.operations }
await this.db.collection(domain).updateOne({ _id: tx.objectId }, op)
} }
override tx (tx: Tx): Promise<void> { override tx (tx: Tx): Promise<void> {