You can use this library:
https://github.com/EqualExperts/mongo-shell-like-query
With this library you can use query string like:
db.users.aggregate([{'$match':{'salary' : {$gte:'from#Long',$lte:'to#Long'}}}, { $group: {_id:'$role', 'age': {$sum: '$age' } } }, { '$sort': { 'age': -1 } }, { '$limit': 5 }])
or
db.users.aggregate({'$match':{'salary' : {$gte:'from#Long',$lte:'to#Long'}}}, { $group: {_id:'$role', 'age': {$sum: '$age' } } }, { '$sort': { 'age': -1 } }, { '$limit': 5 })
passing these strings like this example:
String query = ”db.users.find( { ‘name’ : ‘John’} )”;
MongoQueryParser parser = new MongoQueryParser();
MongoQuery mongoQuery = parser.parse(query, new HashMap());
BasicDBList results = mongoQuery.execute(mongoDB);
It's very very fast to integrate and use in my opinion.
In alternative there is another fantastic library:
http://jongo.org
With this you can use code like:
DB db = new MongoClient().getDB("dbname");
Jongo jongo = new Jongo(db);
MongoCollection friends = jongo.getCollection("friends");
friends.aggregate("{$project:{sender:1}}")
.and("{$match:{tags:'read'}}")
.and("{$limit:10}")
.as(Email.class);