DB db =newMongo("localhost",27017).getDB("dbname");Jongo jongo =newJongo(db);MongoCollection friends = jongo.getCollection("friends");Iterable<Friend> all = friends.find("{name: 'Joe'}").as(Friend.class);Friend one = friends.findOne("{name: 'Joe'}").as(Friend.class);
使用占位符的查询字符串:
friends.find("{name:#, age:#}","Joe",18);//→ will produce {name: 'Joe', age: 18}
friends.find("{address: #}",newAddress(..));//→ will marshall Address object
List<String> ages =Lists.newArrayList(22,63);
friends.find("{age: {$in:#}}", ages);//→ will produce {age: {$in:[22,63]}}
写关注更新: