【发布时间】:2019-02-21 14:19:38
【问题描述】:
我有一个查询,我需要使用$sort 对许多不同的语言不区分大小写。我读到了metadata sort,但我不明白它在我的查询中是如何工作的,或者我怎样才能使排序对许多语言不区分大小写(utf-8)
我的查询
let sort;
if (sortDetailServices.field === "employee.name") {
sort = {
"employee.name": sortDetailServices.status ? 1 : -1
}
}
Schedule.aggregate([{
'$match': findTerm
},
{
'$facet': {
'totalizer': [{
'$group': {
'_id': '$service.id',
'count': {
'$sum': 1
},
'totalValue': {
'$sum': '$value'
},
'totalComission': {
'$sum': '$comissionValue'
}
}
},
{
'$group': {
'_id': null,
'storesCount': {
'$push': {
'store': '$_id',
'count': '$count'
}
},
'totalValue': {
'$sum': '$totalValue'
},
'totalServices': {
'$sum': '$count'
},
'totalComission': {
'$sum': '$totalComission'
}
}
}
],
'data': [{
'$project': {
'employee.name': 1,
'value': 1,
'scheduleStart': 1,
'scheduleEnd': 1,
'comissionValue': 1,
'status': 1,
'paymentMethod': 1
}
},
{
'$sort': sort
},
{
'$skip': req.body.limit * req.body.page
},
{
'$limit': req.body.limit
}
],
}
}
]
...
【问题讨论】: