案例不敏感的搜索电子邮件字段,作为mongoDB中的索引
我的用户收集(用户
)由电子邮件
field(以及其他一些索引)索引。 试图查找具有带有电子邮件的电子邮件的所有文档,该电子邮件以搜索术语案例不敏感开头(试图实现Serach-suggest逻辑)。
我正在使用以下查询:
db.user.getCollection('user').find({
"email" : /^myEmail@gmail/i
})
正如我所理解的,当使用Regex时,我们无法使用索引功能,因此我的查询运行速度非常慢。
是否有一种实现此类的方法以搜索逻辑,而不是使用mongoDB(或其他Atlas功能)提交的索引,该索引利用索引字段超过了大型集合,或者我应该为此使用其他技术吗?
编辑 尝试了文本索引,它没有我预期的。 mongo文本搜索对待myemail@gmail
作为2个不同的文本令牌myemail
and code> gmail ,因此我得到的结果匹配myemail
和结果匹配gmail
。这不是我想要的。
My collection of users (user
) is indexed by the email
field (and some other indexes).
Trying to find all documents that has an email that has an email which starts with a search term case insensitive (trying to implement serach-suggest logic).
I'm using the following query:
db.user.getCollection('user').find({
"email" : /^myEmail@gmail/i
})
As I understood, when using regex we are not able to use the index capabilities hence my query runs very slow.
Is there a way to implement such starts with search logic over indexed filed using MongoDB (or additional Atlas capabilities) leveraging the indexed field over large collection or should I use different technology for that matter?
Edit
Tried text indexes and it didn't work as I expected. Mongo text search treats myEmail@gmail
as 2 different text tokens myEmail
and gmail
so I'm getting results matching myEmail
and results matching gmail
. It is not what I'm looking for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论