regex - Morphia mongoDB 通配符查询

标签 regex mongodb wildcard morphia mongodb-java

直截了当的问题,有人知道如何使用链接到 mongoDB 数据库的 morphia 进行通配符查询吗?

这就是 mongo 语句的样子:

Mongo:db.users.find({name:/Joe/})
SQL: SELECT * FROM users WHERE name LIKE "%Joe%"

我的 morphia 语句如下所示:

Morphia:ds.find(File.class, "filename","/test/").order("filename").asList();

我的数据库中有文件名,例如 test1、test 等

如果有人可以告诉我它是否可能与吗啡一起使用,将不胜感激。

谢谢

最佳答案

您所说的“通配符”实际上是“Regular Expression”。

表示正则表达式的 Java 类是 Pattern .您可以将这些传递给 Morphia 的 Query 对象的过滤器方法。

// create a regular expression which matches any string which includes "test"
Pattern regexp = Pattern.compile("test");
// use this regular expression to create a query
Query q = ds.createQuery(File.class).filter("filename", regexp).sort("filename");

关于regex - Morphia mongoDB 通配符查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12371299/

相关文章:

php - 将 eregi 函数转换为 php 5.3

python - 在 Python 中,如何列出与 POSIX 扩展正则表达式 `[:space:]` 匹配的所有字符?

java - 扩展程序参数中的通配符

windows - 为什么我在 Perl 中打开的管道中的 * 在 Windows 上不起作用?

javascript - 没有 www 但最后带有 .html 的 url 的正则表达式?

regex - 用 & 替换 & 的正则表达式

c# - 如何查看 mongoDB 中的任何更改(新行)?

javascript - 如何使用 Mongoskin 支持模式。

javascript - 如何计算 MongoDB 中的实例数

SQL 更新替换语句