core: fix db pagination filter

This commit is contained in:
undefined committed 2025-03-22 10:59:06 +08:00
1 parent 3a776c3010
commit 917ed3d555
1 file changed
+2 -6
+2 -6
View File
@@ -144,12 +144,8 @@ export class MongoService extends Service {
cursor: FindCursor<T>, page: number, pageSize: number, cursor: FindCursor<T>, page: number, pageSize: number,
): Promise<[docs: T[], numPages: number, count: number]> { ): Promise<[docs: T[], numPages: number, count: number]> {
if (page <= 0) throw new ValidationError('page'); if (page <= 0) throw new ValidationError('page');
let filter = {}; // this is for mongodb driver v6
for (const key of Object.getOwnPropertySymbols(cursor)) { const filter = (cursor as any).cursorFilter;
if (key.toString() !== 'Symbol(filter)') continue;
filter = cursor[key];
break;
}
const coll = this.db.collection(cursor.namespace.collection as any); const coll = this.db.collection(cursor.namespace.collection as any);
const [count, pageDocs] = await Promise.all([ const [count, pageDocs] = await Promise.all([
Object.keys(filter).length ? coll.count(filter) : coll.countDocuments(filter), Object.keys(filter).length ? coll.count(filter) : coll.countDocuments(filter),