简体   繁体   中英

Overridding default batch size in Mongodb connection

I'm looking for some code to override the default batch size of the Mongodb cursor in java.

Similar to one achieved by:

com.mongodb.Mongo mClient = new com.mongodb.MongoClient(context.MongoDBServerName, context.MongoDBPort);

com.mongodb.DB db = mClient .getDB(context.MongoDatabase);

db.collection.find().batch_size(40)

But I want it to be done in the db connection object itself instead of during the find query.

So that I could use the same for all queries.

Looks like, there is no other place to configure this batchSize value. Batch size can be configured only at cursor level.

In your code, batchSize method name is wrong. It should be as follows

db.users.find().batchSize(10)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM