diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 14c1d93de6..f1c07946cc 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -543,6 +543,14 @@ export class LiveQuery extends TxProcessor implements Client { await this.sort(q, tx) const udoc = q.result.find((p) => p._id === tx.objectId) await this.updatedDocCallback(udoc, q) + } else if ( + this.client.getHierarchy().isDerived(tx.objectClass, q._class) && + q.options?.total === true && + q.options.limit === q.result.length + ) { + // we can make object is not matching criteria, but it can be in not limited results, total can be changed + await this.refresh(q) + return } await this.handleDocUpdateLookup(q, tx) } @@ -632,7 +640,7 @@ export class LiveQuery extends TxProcessor implements Client { private async refresh (q: Query): Promise { const res = await this.client.findAll(q._class, q.query, q.options) - if (!deepEqual(res, q.result)) { + if (!deepEqual(res, q.result) || (res.total !== q.total && q.options?.total === true)) { q.result = res q.total = res.total await this.callback(q) diff --git a/server/mongo/src/storage.ts b/server/mongo/src/storage.ts index 6679809239..46239d5b37 100644 --- a/server/mongo/src/storage.ts +++ b/server/mongo/src/storage.ts @@ -562,6 +562,9 @@ abstract class MongoAdapterBase implements DbAdapter { cursor.maxAwaitTimeMS(30000) const res = await cursor.toArray() + if (options?.total === true && options?.limit === undefined) { + total = res.length + } return toFindResult(res, total) }