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 = {}