MongoCollection<Document> collection = db.getCollection("test");
/*******************mongodb根据多个字段查询模糊查询某个值*******************/
//定义一个BasicDBList
BasicDBList endList = new BasicDBList();
//定义最内层的查询 BasicDBObject
BasicDBObject autoStart = new BasicDBObject();
BasicDBObject autoEnd = new BasicDBObject();
//定义最外层的查询 BasicDBObject
BasicDBObject basicDBObject = new BasicDBObject();
Pattern pattern = Pattern.compile("^.*阳光.*$",Pattern.CASE_INSENSITIVE);
autoStart.append("address", pattern);
autoEnd.append("communityName", pattern);
endList.add(autoStart);
endList.add(autoEnd);
basicDBObject.append("$or",endList);
basicDBObject.append("districtName", "渝北区");
BasicDBObject projection = new BasicDBObject();
projection.append("districtName", 1);
projection.append("communityName", 1);
projection.append("address", 1);
projection.append("cityName", 1);
FindIterable<Document> docs = collection.find(basicDBObject).projection(projection);