I'm trying to figure out the advantage of Jongo over simply unmarshalling the json command using (DBObject)JSON.parse(...) and using the DBObject in the below fashion.
Is there a performance advantage?
    @Override
public List<T> getEntityList(Integer limit, String query) throws Exception {
    log.entering(DaoImpl.class.toString(), "getEntityList, with criteria of " + query);
    DBObject criteriaObject = null;
    ArrayList<T> list = new ArrayList<T>();
    if (query != null)
        criteriaObject = (DBObject)JSON.parse(query);
    DBCursor cursor = null;
    try {
        if (criteriaObject != null) {
            log.log(Level.FINEST, "getting the objects using a search criteria: " + criteriaObject);
            cursor = MongoDB.getInstance().getCollection(collection).find(criteriaObject);
        } else {
            log.log(Level.FINEST, "getting the objects without a criteria");
            cursor = MongoDB.getInstance().getCollection(collection).find();
        }
        ............etc, etc, etc
Thanks!
Jongo .3 unmarshalls Mongo query with the same JSON.parse(query). The advantage is the way you get the results from the database. In your example, you have to iterate through a cursor, adapting every property and sub property by yourself. 
DBObject dbo = JSON.parse("{age: 18}");
DBCursor results = users.find(dbo);
for (DBObject result : results) {
    User user = new User();
    user.setUsername((String) result.get("username"));
    user.setAge((Integer) result.get("age"));
    user.setAddress(new Address(..));
}
With Jongo you directly manipulate objects:
Iterable<User> users = collection.find("{age: 18}").as(User.class);
Jongo's performance is nearly equal to the driver's.
Here is a list of few advantages to use jongo:
Almost all queries can be templated :
friends.find("{name:#, age:#}", "Joe", 18)
Binded parameters can be BSON Primitives or any complex type :
friends.find("{address: #}", new Address(..)); 
BTW your GSON un/marshaller can be integrated into Jongo by implementing a Mapper.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With