mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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,
|
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),
|
||||||
|
|||||||
Reference in new issue
Block a user