this code block I am using to Fetch Products from DB. Which have StoreId = 3.
int PER_BATCH_COUNT = 1000;
List<Product> dataList = new ArrayList<Product>();
int count = 77235; //no of records in DB
int iterations = BigDecimal.valueOf(count).divide(BigDecimal.valueOf(PER_BATCH_COUNT), RoundingMode.UP).intValue();
int iterationNo = 0;
/*this works as a page no, to calcualte the next start index*/
int rowCount = 1;
while(iterations != 0) {
iterationNo++;
log.info("Getting result for Iteration No: " + iterationNo);
int startIndex = (iterationNo-1)*PER_BATCH_COUNT+1;
Query query = Query.query(Criteria.where(SearchParameters.STORE_ID.getAttributeName()).is("3"));
query.skip(startIndex);
query.limit(PER_BATCH_COUNT);
dataList.addAll(mongoTemplate.find( query, Product.class));
iterations--;
}
return dataList;