[英]How to sort in Mongo Spring @Aggreation?
I have我有
@Aggregation({
"{'$match': {'$and': [ { 'xId' : ?0 },{'pDay': { '$gte': ?1 } },{'pDay': { '$lte': ?2 } }, ] } }",
"{'$sort': {'x2': 1,'x3': 1}}",
"{$group: { _id: $pDay, abcs: { $addToSet : $$ROOT }}}",
"{'$limit': ?4}",
"{'$skip': ?5}"
})
but as result I see one record with abcs list, but items in in are unsorted by x2.但结果我看到一条带有 abcs 列表的记录,但其中的项目未按 x2 排序。
Sames is for sort after group. Sames 用于按组排序。
public class XView {
@Id
Long pDay;
List<X> abcs;
}
@Document
public class X {
String xId;
String x2;
String x3;
}
$group
does not preserve the order. $group
不保留订单。
@Aggregation({
"{'$match': {'$and': [ { 'xId' : ?0 },{'pDay': { '$gte': ?1 } },{'pDay': { '$lte': ?2 } }, ] } }",
"{$group: { _id: $pDay, abcs: { $addToSet : $$ROOT }}}",
"{'$sort': {'x2': 1,'x3': 1}}",
"{'$limit': ?4}",
"{'$skip': ?5}"
})
https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/ https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/
https://docs.mongodb.com/manual/core/aggregation-pipeline/ https://docs.mongodb.com/manual/core/aggregation-pipeline/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.