this question is very similar to another post
I basically want to use the mongodb version of the sql "like" '%m%' operator
but in my situation i'm using the java api for mongodb, while the other post is using mongodb shell
i tried what was posted in the other thread and it worked fine
BasicDBObject q = new BasicDBOBject();
You need to pass an instance of a Java RegEx (java.util.regex.Pattern):
BasicDBObject q = new BasicDBObject(); q.put("name", java.util.regex.Pattern.compile(m)); dbc.find(q);
This will be converted to a MongoDB regex when sent to the server, as well as any RegEx flags.