Я хочу разделить cropYield на cropAcres, мой формат данных следующий, и у меня их 1000. Поэтому мне нужно получить массив этого cropYield/cropAcres
для каждой записи в виде массива. это моя коллекция FarmerCropDataLog .
{
"_id": "5ce681e14e8e8aec5a7e9ac4",
"_class": "com.cheruvu.webapp.entity.FarmerCropDataLog",
"farmerId": "5cdc16214e8e21271cb3af5e",
"cropData": {
"cropName": "COTTON",
"crop": "COTTON",
"cropAcres": 2,
"cropYield": 10,
"cropPrice": 9000
},
"villageId": "5b0ed0bd77c8ae9704f65c97",
"creationTime": "1558610401404",
"lastUpdated": "1558610996163",
"state": "ACTIVE"
}
Это то, что я пробовал.
// I need to fetch all users(farmers) with same VillageId, same crop and which are added in last year.
Criteria criteria = Criteria.where(FarmerCropDataLog.Constants.CROP).is(getComparisonSheet.getCrop().name())
.and(FarmerCropDataLog.Constants.VILLAGE_ID).is(villageId)
.and(FarmerCropDataLog.Constants.CREATION_TIME).gte(LAST_YEAR);
MatchOperation matchOperation = Aggregation.match(criteria);
// then via projection i am getting cropYield and divide it via cropAcres.
ProjectionOperation projectionOperation = Aggregation.project(FarmerCropDataLog.Constants.CROP_YIELD);
ProjectionOperationBuilder builder = new ProjectionOperationBuilder("op1", projectionOperation, null);
builder = builder.divide(FarmerCropDataLog.Constants.CROP_ACRES);
projectionOperation = builder.as(GetYieldComparisonResponse.Constants.MAX_YIELD);
// and at last i am running this operation via following code.
AggregationOptions aggregationOptions = Aggregation.newAggregationOptions().allowDiskUse(true).explain(false)
.cursor(new BasicDBObject("batchSize", 100)).build();
Aggregation aggregation = Aggregation.newAggregation(matchOperation,projectionOperation)
.withOptions(aggregationOptions);
AggregationResults<GetYieldComparisonResponse> aggregationResults = farmerCropDataLogDAO
.runAggregation(aggregation, FarmerCropDataLog.class, GetYieldComparisonResponse.class);
результат, полученный этим, пуст. Я не понимаю, почему?