java – Jongo vs(DBObject)JSON. parse
•
Java
I try to find out the advantages of Jongo instead of simply using (dbobject) JSON Parse (...) unmarshalls the JSON command and uses dbobject in the following way
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
thank you!
Solution
The Jongo. 3 unmarshalls Mongo query uses the same JSON Parse (query) The advantage is the way to get results from the database In your example, you have to traverse the cursor and adjust each attribute and sub attribute 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 can directly manipulate objects:
Iterable<User> users = collection.find("{age: 18}").as(User.class);
Jongo's performance is almost equal to that of the driver
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码