JavaでMongoDBを検索するサンプル

サンプルコード
package com.changfa.study;
import org.bson.Document;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;

public class MongoTest1 {
public static void main(String[] args) {
MongoClient client = new MongoClient(“172.17.2.100", 27017);
MongoDatabase db = client.getDatabase(“employeeDB");

MongoCollection<Document> mc = db.getCollection(“empinfo");

long count = mc.count();

System.out.println(count);

for (Document dmt : mc.find()) {
System.out.println(dmt);
}

}
}

Java

Posted by arkgame