mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: fix db pagination filter
This commit is contained in:
1 file changed
+2
-6
@@ -144,12 +144,8 @@ export class MongoService extends Service {
|
||||
cursor: FindCursor<T>, page: number, pageSize: number,
|
||||
): Promise<[docs: T[], numPages: number, count: number]> {
|
||||
if (page <= 0) throw new ValidationError('page');
|
||||
let filter = {};
|
||||
for (const key of Object.getOwnPropertySymbols(cursor)) {
|
||||
if (key.toString() !== 'Symbol(filter)') continue;
|
||||
filter = cursor[key];
|
||||
break;
|
||||
}
|
||||
// this is for mongodb driver v6
|
||||
const filter = (cursor as any).cursorFilter;
|
||||
const coll = this.db.collection(cursor.namespace.collection as any);
|
||||
const [count, pageDocs] = await Promise.all([
|
||||
Object.keys(filter).length ? coll.count(filter) : coll.countDocuments(filter),
|
||||
|
||||
Reference in new issue
Block a user