获取client 默认连接本地
MongoClient mongoClient = new MongoClient();
查看源码:this(defaultHost(), defaultPort());
获取DB
MongoDatabase db = mongoClient.getDatabase("pcs");
连接collection 操作
插入
db.getCollection("product").insertOne( new Document("topProductTypeId", 1).append("topProductTypeName","跟团游").append("subProductTypeId",0)); 更新UpdateResult result= db.getCollection("product").updateMany(new Document("dates.departDate", "2015-11-5"), new Document("$set", new Document("dates.$.price",999)));
查询
FindIterable<Document> iterable=db.getCollection("product").find(new Document("dates.price",new Document("$gt",9995)));iterable.forEach(new Block<Document>() { @Override public void apply(final Document document) { System.out.println(document); } });