简体   繁体   English

如何使用 mongoDb C# 驱动程序在 MongoDb asp.net 核心应用程序中处理多种语言的排序

[英]How to deal with sorting for multiple Language in MongoDb asp.net core application using mongoDb C# driver

I have a collection in which title can be in multiple language我有一个集合,其中的标题可以是多种语言

example: If my Platform language is Spanish all the titles will be in Spanish.例如:如果我的平台语言是西班牙语,则所有标题都是西班牙语。 so how can I sort with Title那么我如何用标题排序

public class Collection
    {
        public string Id { get; set; }
        public string Title { get; set; }
    }

there are two Ways to sort,有两种排序方式,

  1. Mongo Linq蒙戈林克
  2. Fluent Aggregate Syntax流利的聚合语法

for both cases you have to use AggregateOptions and Set Collation.Local to your desired local, you can toggle other flags to get your appropriate case sorting as well.对于这两种情况,您都必须使用AggregateOptions并将Collat​​ion.Local设置为所需的本地,您还可以切换其他标志以获得适当的案例排序。

collation: {
   locale: <string>,
   caseLevel: <boolean>,
   caseFirst: <string>,
   strength: <int>,
   numericOrdering: <boolean>,
   alternate: <string>,
   maxVariable: <string>,
   backwards: <boolean>
}

For MongoDb Linq对于 MongoDb Linq

var option = new AggregateOptions
                {
                    Collation = new Collation(searchParam.Local, false)
                };


        var list = collection.AsQueryable(option).OrderBy(x=>x.Title).
                ToListAsync(ct);

For Fluent Aggregate Syntax对于 Fluent 聚合语法

 var option = new AggregateOptions
            {
                Collation = new Collation(searchParam.Local, false)
            };



  var result collection.Aggregate(option).Match(searchFilter).
                Sort(Builders<Collection>.Sort.Ascending(x=>x.Title).
                ToListAsync(ct);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将MongoDB驱动程序与C#ASP.NET核心API框架一起使用? - How can I use the MongoDB Driver with C# ASP.NET Core API framework? MongoDB C# .NET 驱动程序 ASP.NET Core 不支持的过滤器 - MongoDB C# .NET Driver ASP.NET Core Unsupported Filter 如何使用 MongoDB 将动态 JSON 属性发布到 C# ASP.Net Core Web API? - How to post a dynamic JSON property to a C# ASP.Net Core Web API using MongoDB? ASP.NET MVC 4 C#加mongodb驱动程序 - asp.net mvc 4 c# plus mongodb driver 如何在 NET 4.5 应用程序中使用 MongoDB c# 驱动程序? - How to use MongoDB c# driver in NET 4.5 application? 将 ASP.NET 核心标识与 MongoDB 一起使用 - Using ASP.NET Core Identity with MongoDB 使用 MongoDB C# (ASP.NET) 的登录表单 - Login form using MongoDB C# (ASP.NET) asp.net c#和mongodb模型 - asp.net c# and mongodb models 我应该使用C#驱动程序还是Javascript驱动程序,使用MongoDB和ASP.NET MVC构建Web应用程序 - Building Web Apps using MongoDB and ASP.NET MVC, Should I Use C# Drivers or Javascript Driver 如何使用 BsonDocument C# .NET 驱动程序在 MongoDB 中将多个投影和查找作为聚合执行? - How to perform multiple projections and lookups as aggregate in MongoDB using BsonDocument C# .NET driver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM