【发布时间】:2020-11-09 13:07:29
【问题描述】:
我想在使用聚合后对我的产品进行排序,在我的聚合管道中,我在 $facet 阶段使用 $sort。实际上排序对所有字段都很好,直到我尝试对字符串字段(名称)升序/降序进行排序。
问题是排序在我的土耳其语中无法正常工作。所以我正在使用排序选项。
我正在使用 C#。
通常我使用如下排序规则区域设置
PipelineDefinition<BsonDocument, Model> pipeline = new BsonDocument[]
{
//some stages,
new BsonDocument().Add("$sort", new BsonDocument().Add("sortingParameter", -1)),
//some stages
};
var options = new AggregateOptions() { Collation = new Collation("tr") };
var cursor = _collection.Aggregate(pipeline, options);
它正在工作,这里没问题。
但是我的一些查询比上面的例子更复杂,例如 (下面我显示的是我的查询的缩短 BsonDocument 版本)
db.getCollection('collName').aggregate([
{"$match": { // match operations }
},
{"$facet": {
"product_list": [
{"$group": {"_id": { /some grouping parameters }}},
{ "$sort": { "_id.Name": -1.0 } },
{ "$project": { // some projects }}
]}}])
对于上述查询,我使用相同的聚合选项
var options = new AggregateOptions() { Collation = new Collation("tr") };
但排序结果不正确。当我尝试删除 $match 阶段时,我不知道它是如何工作的。
那么,有没有办法解决这个问题,或者这种查询是不可能的?
【问题讨论】:
标签: mongodb sorting aggregation-framework collation facet