“喜欢" MongoDB中的命令(mongomapper) [英] "LIKE" command in MongoDB(mongomapper)

查看:97
本文介绍了“喜欢" MongoDB中的命令(mongomapper)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在MongoDB中像SQL一样使用过滤器数据在MongoDB中执行"LIKE"操作,而不是在rails应用程序上使用gem mongomapper? .谢谢

how to use filter data as sql do "LIKE" in MongoDB, instead I using gem mongomapper on my rails apps? .thanks

推荐答案

如果要在字符串上查找部分匹配项,则可以使用正则表达式进行查询.这是mongomapper文档的相关部分:

If you're looking for partial matches on a string you can query with a regular expression. Here's the relevant part of the mongomapper docs:

http://api.mongodb.org/ruby/current/file.TUTORIAL.html#Querying_with_Regular_Expressions

值得从Mongodb文档中注意到这一点:

Worth noting this from the Mongodb docs:

对于简单的前缀查询(也称为根正则表达式),例如/^ prefix/,数据库将在可用且适当时使用索引(与大多数对LIKE'prefix%'表达式使用索引的SQL数据库一样).仅在标记中没有i(不区分大小写)的情况下才有效."

"For simple prefix queries (also called rooted regexps) like /^prefix/, the database will use an index when available and appropriate (much like most SQL databases that use indexes for a LIKE 'prefix%' expression). This only works if you don't have i (case-insensitivity) in the flags."

这篇关于“喜欢" MongoDB中的命令(mongomapper)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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