【发布时间】:2019-04-09 02:17:47
【问题描述】:
我有这个聚合,我正在使用小写和 UTF-8 对字段 (_id.name) 进行排序,但我无法对 "á" 或 "Á" 之类的字符串进行排序喜欢。如何对 utf-8 和小写字符串进行排序?
聚合:
Schedule.aggregate([{
$match: {
store: req.body.store,
scheduleStart: {
$lte: start,
$gte: req.body.period
},
status: {
$in: resultStatus
}
}
},
{
$group: {
_id: {
name: "$employee.name",
id: "$employee.id"
},
totalValue: {
$sum: "$value"
},
totalServices: {
$sum: 1
},
totalComission: {
$sum: "$comissionValue"
}
}
},
{
'$addFields': {
'ticket': {
'$divide': ['$totalValue', '$totalServices']
}
}
},
{
$sort: {
"_id.name": 1
}
},
{
$skip: req.body.limit * req.body.page
}
编辑
现在我使用这样的排序规则:
Schedule.aggregate([{
...
{
$sort: {
"_id.name": 1
}
},
{
$skip: req.body.limit * req.body.page
}
], { "collation": { "locale": "pt" }}).exec((error, response) => {
if (error) res.status(500).send({
error,
code: 0,
message: langs[req.query.lang].somethingWentWrong
});
错误: MongooseError: Callback must be a function, got [object Object]
【问题讨论】:
-
@AnthonyWinzlet 如何在查询中传递排序规则和语言环境?
标签: mongodb sorting mongoose nosql aggregation-framework