BSONObject query = new BasicBSONObject();
query.put("city", "西安");
我想查询city这个字段中 所有含有西安的 应该怎么写呢?
SequoiaDB数据库中怎样使用like来查询一个字段呢?能不能给个例子呢?
可以使用正则表达式来实现字符匹配的功能:
http://www.sequoiadb.com/documen ... /topics/pregex.html
BSONObject matcher = new BasicBSONObject();
Pattern obj = Pattern.compile("西安",Pattern.CASE_INSENSITIVE);
matcher.put("city", obj);
谢谢你啦 亲:)
如何转换成query.put("title", "{$regex:"+"'"+keywords+"'}");
也就是使用put的方式如何使用?
更正一下,之前构造正则表达式的方法有问题, 须用如下方法构造正则表达式:
Pattern obj = Pattern.compile(keywords, Pattern.CASE_INSENSITIVE);
matcher.put("title", obj);
这个查询等价于等于啊!如何查询只要含这个字段的。相当于%like%?
$regex:"abc" 等于 like "%abc%"
这样做是等于西安的,而不是含西安的字段都能查询出来。
tmp.put( "{$regex", keywords );多打了一个括号
cl.query(matcher,null,null,null)