基本上这是我的问题:
如何用“喜欢”查询MongoDB?
但我想这里的所有答案都适用于你使用mongodb shell命令行,那么它的等价物是什么 db.users.find({"name": /.*m.*/})
当我们使用java时。
这是我想要做的
DBCollection coll = MongoDBUtil.getDB().getCollection("post_details");
BasicDBObject query = new BasicDBObject();
query.put("price", new BasicDBObject("$gt", 5).append("$lt", 8));
/*what should i write instead of this line*/
query.put("title", "/.*m.*/");
DBCursor cur = coll.find(query);
对于此问题,您应该使用正则表达式,如下例所示:
BasicDBObject query = new BasicDBObject();
Pattern regex = Pattern.compile("the title you are looking for"); // should be m in your case
query.put("title", regex);
对于此问题,您应该使用正则表达式,如下例所示:
BasicDBObject query = new BasicDBObject();
Pattern regex = Pattern.compile("the title you are looking for"); // should be m in your case
query.put("title", regex);
以上面的示例为参考,但使用Filters类:
Pattern regex = Pattern.compile("title you look for");
Bson filter = Filters.eq("nombre", regex));