From 3ab72eb819a067633c60092395548c6d425e4a1e Mon Sep 17 00:00:00 2001 From: Andrey Platov Date: Wed, 8 Sep 2021 10:34:48 +0200 Subject: [PATCH] fixes #159 Signed-off-by: Andrey Platov --- server/mongo/src/storage.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/mongo/src/storage.ts b/server/mongo/src/storage.ts index 5a750b7d21..6b08e07532 100644 --- a/server/mongo/src/storage.ts +++ b/server/mongo/src/storage.ts @@ -19,11 +19,6 @@ import type { DbAdapter, TxAdapter } from '@anticrm/server-core' import { MongoClient, Db, Filter, Document, Sort } from 'mongodb' -function translateQuery (clazz: Ref>, query: DocumentQuery): Filter { - // return Object.assign({}, query, { _class: clazz }) - return query as Filter -} - function translateDoc (doc: Doc): Document { return doc as Document } @@ -38,9 +33,14 @@ abstract class MongoAdapterBase extends TxProcessor { async init (): Promise {} + private translateQuery (clazz: Ref>, query: DocumentQuery): Filter { + const classes = this.hierarchy.getDescendants(clazz) + return Object.assign({}, query, { _class: { $in: classes } }) + } + private async lookup (clazz: Ref>, query: DocumentQuery, options: FindOptions): Promise> { const pipeline = [] - pipeline.push({ $match: translateQuery(clazz, query) }) + pipeline.push({ $match: this.translateQuery(clazz, query) }) const lookups = options.lookup as any for (const key in lookups) { const clazz = lookups[key] @@ -76,7 +76,7 @@ abstract class MongoAdapterBase extends TxProcessor { if (options.lookup !== undefined) { return await this.lookup(_class, query, options) } } const domain = this.hierarchy.getDomain(_class) - let cursor = this.db.collection(domain).find(translateQuery(_class, query)) + let cursor = this.db.collection(domain).find(this.translateQuery(_class, query)) if (options !== null && options !== undefined) { if (options.sort !== undefined) { const sort: Sort = {}