When I use the aggregate function to get all users with the same name, the results returned by the API are not sorted even though I specify to sort by the 'name' field.
const aggregateQuery: any = [
{ $group: { _id: '$name', count: { $sum: 1 }, users: { $push: '$$ROOT' } } },
{ $match: { count: { $gt: 1 } } },
{ $unwind: '$users' },
{ $replaceRoot: { newRoot: '$users' } },
{ $sort: { name: 1 } }
];`
const users = await this.userRepository.getModel().aggregate(aggregateQuery).exec();
Despite my efforts, the order of the records remains unsorted.