In Java using MongoTemplate perform batch processing of data

/ **
* Mongo amount of data to be processed in relatively long time, batch processing may be divided
* batch processed data using MongoTemplate
* skip (num) .limit (10000 ) of data after the skip num, data fetch 10000
* /

static void main public (String [] args) {
// query all valid record
int total = (int) mongoTemplate.count ( query (where ( "deletedFlag"). is (false)), User.class, "user" );
// 10000 in accordance with a data batch, the batch is divided
int size = Total / 10000;
int number% Total = 10000;
// 0 remainder, as the rest of the record is not a lot
if (number! 0 =) {
size = size +. 1;
}
for (int I = 0; I <size; I ++) {
int NUM = (I * 10000);
List <the User> Users mongoTemplate.find = (Query (WHERE ( "deletedFlag ") .is (to false)) Skip (NUM) .limit (10000), User.class,." User ");
for (the User User: Users) {
// each record operating data
}
}
}

Guess you like

Origin www.cnblogs.com/wueryuan/p/12125370.html