I use aggregate to get all users have same name, but whenever I query to this API, the results return are not sorted even thought I add $sort by '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();
The order of the records is not sorted