MONGODBDB enable Wiredtiger engine and zlib compression

Source: Internet
Author: User



public static void Main (string[] args) {

Mongoclientoptions.builder build = new Mongoclientoptions.builder ();

Maximum number of connections to data 50

Build.connectionsperhost (50);

If all current connection are in use, there can be 50 threads queued for each connection

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);


Gets the database test, does not exist, it automatically establishes the database

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 must be close to release resources after use

Client.close ();

System.out.println ("Ooooooooooooookkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");

}

Determine if collection exists

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 enable Wiredtiger engine and zlib compression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.