通过find方法查询集合中的文档信息
--------------------------------------------------------
find()
查询所有文档信息,返回FindIterable
我们可以通过FindIterable的forEach方法取得document信息
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase("test"); MongoCollection doc = db.getCollection("text");
FindIterable iter = doc.find(); iter.forEach(new Block() { public void apply(Document _doc) { System.out.println(_doc.toJson()); } });
--------------------------------------------------------------------
条件查询
new Document( , )
field为查询字段,value为查询值,也可以通过过滤器Filters,Filters提供了一系列查询条件的静态方法
相等 — =
FindIterable iter = doc.find(new Document("name","张三"));
// 或者 FindIterable iter = doc.find(new Document("age",new Document("$eq",24)));