简体   繁体   English

在带有 C# 的点网核心中使用带有 mongo 驱动程序的过滤器时如何忽略大小写

[英]How to ignore case when using filters with the mongo driver in dot net core with C#

I have an aggregates pipeline query as below:我有一个聚合管道查询,如下所示:

string [] sids   = { array of Student ids here };
string deptName = "math";
var pipeline = new BsonDocument[]
    {
        new BsonDocument("$match",
            new BsonDocument
            {
                {"studentid", new BsonDocument("$in",BsonArray.Create(sids))},
                {"dept",BsonRegularExpression.Create(new Regex( dept, RegexOptions.IgnoreCase))}
            }
        ),
            new BsonDocument("$sort",new BsonDocument("CardSwipeTimestamp", -1)),
                               
            new BsonDocument("$group",
                new BsonDocument{
                        { "_id",
                            new BsonDocument
                            {
                                { "studentid","$studentid" },
                                { "dept","$dept"}
                            }
                        },
                        { "Status",new BsonDocument("$first", "$Status")},
                        { "CardSwipeTimestamp",new BsonDocument("$first", "$CardSwipeTimestamp")}
                    }
                ),
       new BsonDocument("$project",
            new BsonDocument
            {
                { "_id", 0 },
                { "studentid", "$_id.studentid" },
                { "dept", "$_id.dept" },
                { "Status", "$Status" },
                { "CardSwipeTimestamp", "$CardSwipeTimestamp" }
            }
        ),
         new BsonDocument("$skip",0),
         new BsonDocument("$limit",3),
    };

collectionName.Aggregate<BsonDocument>(pipeline).ToList()

These only returns a value if the department passed in matches the case of what is stored in the collection.如果传入的部门与集合中存储的内容匹配,则这些仅返回一个值。

How to ignore the case of the incoming parameter when doing a search using the above query?使用上述查询进行搜索时如何忽略传入参数的大小写?

You could convert the two sides of the match expression to lowercase with ToLower()您可以使用ToLower()将匹配表达式的两侧转换为小写

ToLower(left operand).equal(ToLower(right operand))  //so we can ignore case.

暂无
暂无

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

相关问题 如何在 Z2D50972FCECD70612895456 中使用 C# mongo Db 驱动程序将多个文档组合/合并到一个 c# object - How to combine/merge multiple document to one c# object using C# mongo Db driver in .net core 如何使用 C# Dot Net Core 压缩图像大小 - How to compress the image size using C# Dot Net Core .NET Core 中的 Mongo C# 驱动程序和 ObjectID JSON 字符串格式 - Mongo C# Driver and ObjectID JSON String Format in .NET Core 搜索时如何忽略C#中的大小写 - How to ignore case in c# when searching 在.NET Core上调用Mongo的C#驱动程序时无法加载类型&#39;System.Runtime.Remoting.Messaging.CallContext&#39; - Could not load type 'System.Runtime.Remoting.Messaging.CallContext' when calling into Mongo's C# Driver on .NET Core 如何在不使用 Builders 的情况下使用 .net(c#) 驱动程序更新 mongo db 中的文档? - How can i update document in mongo db using .net(c#) driver without using Builders? 使用 Mongo C# 驱动程序时,查询排序是在 Mongo 内发生还是在 C# 级别发生? - When using the Mongo C# driver, does query sorting occur within Mongo, or at the C# level? C#点网核心动作过滤器-如何读取响应 - c# dot net core action filter - How to read response Mongo C# 驱动程序如何在使用 elemMatch 时从投影中排除元素? - Mongo C# driver How to exclude elements from projection when using elemMatch? 如何在C#中使用mongo驱动程序按条件排序 - How to sort by condition using the mongo driver in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM