I would like to retrieve the following information:
select names from database where names like 'Jon';
but for MongoDB in Java. Essentially, it should return all names that contain the word Jon in them, like Jonathan, Jong etc etc. I know that there is the $in operator in MongoDB, but how do I do the same in Java, using the Java driver? I've been trying to look for it everywhere but am getting nothing. I've tried: query = new BasicDBObject("names", new BasicDBObject("$in", "Jon"));, and query = new BasicDBObject("names", new BasicDBObject("$in", Jon));
But neither of them worked :( Please help!
query = new BasicDBObject("names", new BasicDBObject("$in", "Jon"));, andquery = new BasicDBObject("names", new BasicDBObject("$in", Jon));But neither of them worked :( I did look up Morphia too, but I'm kinda crunching on time, and implementing that is kinda beyond my time frame, especially since I only need one single query.LIKE "%Jon%". To get only those which start with Jon, you would useLIKE "Jon%". The MongoDB$inoperator is for searching in array fields. To search for string fragments, you can use$regexand regular expressions.