public static void main(String[] args) {
创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站制作、网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的洞口网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
MongoClientOptions.Builder build = new MongoClientOptions.Builder();
// 与数据最大连接数50
build.connectionsPerHost(50);
// 如果当前所有的connection都在使用中,则每个connection上可以有50个线程排队等待
build.threadsAllowedToBlockForConnectionMultiplier(50);
build.connectTimeout(1 * 60 * 1000);
build.maxWaitTime(2 * 60 * 1000);
MongoClientOptions options = build.build();
String host="192.168.80.100";
int port=27017;
MongoClient client = new MongoClient(new ServerAddress(host, port), options);
// 获取数据库test,不存在的话,会自动建立该数据库
MongoDatabase db = client.getDatabase("fanyin");
// { storageEngine: {
// wiredTiger: { configString: 'block_compressor=zlib' }}
CreateCollectionOptions createCollectionOptions = new CreateCollectionOptions();
BasicDBObject configString = new BasicDBObject();
configString.put("configString", "block_compressor=zlib");
BasicDBObject bson = new BasicDBObject();
bson.put("wiredTiger", configString);
createCollectionOptions.storageEngineOptions(bson);
boolean isCollectionExist=collectionExists(db, "data");
if(!isCollectionExist){
db.createCollection("data", createCollectionOptions);
}
MongoCollection<Document> users = db.getCollection("data");
for (int i = 0; i < 1; i++) {
Document document = new Document();
document.append("address2", "sichuan chengdu444444444444444444444444");
document.append("address3", "sichuan chengdu44455555555555555555555555555555");
users.insertOne(document);
}
MongoCollection<Document> users1 = db.getCollection("data1");
for (int i = 0; i < 1; i++) {
Document document = new Document();
document.append("address2", "sichuan chengdu444444444444444444444444");
document.append("address3", "sichuan chengdu44455555555555555555555555555555");
users1.insertOne(document);
}
// MongoClient使用完后必须要close释放资源
client.close();
System.out.println("ooooooooooooookkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
}
//判断collection是否存在
private static boolean collectionExists(MongoDatabase database,String collectionName){
final MongoIterable<String> iterable = database.listCollectionNames();
try (final MongoCursor<String> it = iterable.iterator()) {
while (it.hasNext()) {
if (it.next().equalsIgnoreCase(collectionName)) {
return true;
}
}
}
return false;
}
文章标题:mongodbdb启用wiredTiger引擎及zlib压缩
文章源于:/article44/iisjee.html
成都网站建设公司_创新互联,为您提供网站改版、Google、小程序开发、面包屑导航、手机网站建设、网站导航
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联