Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mongodbdb enables wiredTiger engine and zlib compression

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Public static void main (String [] args) {

MongoClientOptions.Builder build = new MongoClientOptions.Builder ()

/ / maximum number of connections with data 50

Build.connectionsPerHost (50)

/ / if all current connection are in use, there can be 50 threads queuing on 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)

/ / get the database test. If it does not exist, the database will be established automatically.

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 users = db.getCollection ("data")

For (int I = 0; I < 1; iTunes +) {

Document document = new Document ()

Document.append ("address2", "sichuan chengdu444444444444444444444444")

Document.append ("address3", "sichuan chengdu44455555555555555555555555555555")

Users.insertOne (document)

}

MongoCollection users1 = db.getCollection ("data1")

For (int I = 0; I < 1; iTunes +) {

Document document = new Document ()

Document.append ("address2", "sichuan chengdu444444444444444444444444")

Document.append ("address3", "sichuan chengdu44455555555555555555555555555555")

Users1.insertOne (document)

}

/ / close must release resources after MongoClient is used.

Client.close ()

System.out.println ("ooooooooooooookkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk")

}

/ / determine whether collection exists

Private static boolean collectionExists (MongoDatabase database,String collectionName) {

Final MongoIterable iterable = database.listCollectionNames ()

Try (final MongoCursor it = iterable.iterator ()) {

While (it.hasNext ()) {

If (it.next () .equalsIgnoreCase (collectionName)) {

Return true

}

}

}

Return false

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report