The Java MongoDB driver, equivalent to this SELECT statement, will look like this:
BasicDBObject fields = new BasicDBObject().append("name", 1); // SELECT name BasicDBObject query = new BasicDBObject().append("name", "Jon"); // WHERE name = "Jon" DBCursor results = yourCollection.find(query, fields); // FROM yourCollection
If you want to find part of a string, you can use the $regex operator:
query = new BasicDBObject("name", new BasicDBObject("$regex", "Jon"));
This will give you all the objects where the name matches the Jon regular expression , which is everything that includes the string "Jon" anywhere.
source share