【发布时间】:2013-01-11 09:00:58
【问题描述】:
我在从 Grails 应用程序在 MongoDB 中发出通配符查询时遇到了一些问题。
基本上我现在的做法是发出带有查询参数数组的find 查询:
db.log.find(criteria) -> where criteria is an array [testId:"test"]
只要我严格查询实际值,它就可以正常工作。但是,为了好玩,我尝试使用通配符搜索:
db.log.find(criteria) -> this time critera = [testId:/.*te.*/]
然而,在查看 Mongo 查询日志后,这将是:
query: { query: { testId: "/.*te.*/" }
因此使查询不是通配符搜索,而是作为字符串查询。 有没有办法在某种意义上仍然使用这种查询概念来解决这个问题?
提前致谢!
【问题讨论】: