如何在 MongoDb 中获取不区分大小写的记录? [英] How to fetch records without case sensitive in MongoDb?

查看:33
本文介绍了如何在 MongoDb 中获取不区分大小写的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似的收藏

{

"email" : "sh@Gmail.com"

}

我的查询应该是这样的,无论大小写,它都必须找到匹配的电子邮件,但它应该完全匹配.

My query should be like , it has to find matching email irrespective of case whether its capital or small but it should match exactly.

在 sql 中,我们会像 where Lower(strEmail) = Lower(@emailParameterPassed) 一样满足这一点.

In sql we will do like where Lower(strEmail) = Lower(@emailParameterPassed) to satisfy this same.

更新

我在这里得到了它.谢谢

如何在 mongoDb 中实现这一点?

How to achieve this in mongoDb?

我正在使用带有 mongoDb 的 c# 本机驱动程序?

I am using c# native driver with mongoDb ?

推荐答案

尽管您复制的答案会给您一个正确的结果,但执行这样的查询并不是一个好主意.如果可以使用普通相等并利用索引,为什么要使用正则表达式(没有索引)?

Nonetheless the answer you are duplicating will give you a correct result, it is not a good idea to do queries like this. Why should you use regex (without indexes ) if you can use normal equal and take advantage of indexes?

sh@Gmail.comsh@gmail.com 之间没有区别,那么为什么不首先以规范形式存储它们,然后使用普通搜索.要更改所有文档,您可以参考我的以前的答案.

There is no difference between sh@Gmail.com and sh@gmail.com so why not to store them in a canonical form in the first place and then to use normal search. To change all the documents, you can refer to my previous answer.

这篇关于如何在 MongoDb 中获取不区分大小写的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆