From 50d4a5a9e5caa30a172330b1d3a38ea2385fd641 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Wed, 7 Apr 2021 20:36:08 -0600 Subject: [PATCH] [FIX] Admin Users list pagination (#21469) --- app/api/server/v1/users.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/api/server/v1/users.js b/app/api/server/v1/users.js index 1d2c693f7ef3..f6f5ab461509 100644 --- a/app/api/server/v1/users.js +++ b/app/api/server/v1/users.js @@ -254,29 +254,29 @@ API.v1.addRoute('users.list', { authRequired: true }, { }, }, }, - { - $skip: offset, - }, - { - $limit: count, - }, { $facet: { - sortedResults: [{ $sort: actualSort }], - totalCount: [{ $count: 'value' }], + sortedResults: [{ + $sort: actualSort, + }, { + $skip: offset, + }, { + $limit: count, + }], + totalCount: [{ $group: { _id: null, total: { $sum: 1 } } }], }, }, ]) .toArray(), ); - const { sortedResults: users, totalCount } = result[0]; + const { sortedResults: users, totalCount: [{ total }] } = result[0]; return API.v1.success({ users, count: users.length, offset, - total: totalCount[0].value, + total, }); }, });