「MongoDB入門」Javaでデータを検索するサンプル

2018年7月25日

Javaコード:
MongoCollection<Document> mc = database.getCollection(collectionName);
//some code
BasicDBObject cft = new BasicDBObject();
cft.put(“name", “gotanno");
FindIterable<Document> ff = mc.find(cft);
MongoCursor<Document> mcr = ff.iterator();
try {
while (mcr.hasNext()) {
System.out.println(mcr.next().toJson());
}
} finally {
mcr.close();
}
long cnt = coll.count(cft);
System.out.println(“検索結果:"+cnt + “件");
mongoClient.close();

Java

Posted by arkgame