Med udgangspunkt i informationen givet af @dnickless var jeg i stand til at løse dette. Jeg vil poste den komplette løsning i håb om, at den hjælper en anden i fremtiden.
Jeg bruger mongodb-driver:3.6.4
Først skulle jeg oprette en brugerdefineret aggregeringsoperationsklasse, så jeg kunne sende en tilpasset JSON mongodb-forespørgsel, der skulle bruges i aggregeringsoperationen. Dette vil tillade mig at bruge pipeline
i en $lookup
som ikke understøttes med den driverversion, jeg bruger.
public class CustomProjectAggregationOperation implements AggregationOperation {
private String jsonOperation;
public CustomProjectAggregationOperation(String jsonOperation) {
this.jsonOperation = jsonOperation;
}
@Override
public Document toDocument(AggregationOperationContext aggregationOperationContext) {
return aggregationOperationContext.getMappedObject(Document.parse(jsonOperation));
}
}
Nu hvor vi har muligheden for at sende en tilpasset JSON-forespørgsel ind i vores mongodb-forårsimplementering, er der kun tilbage at tilslutte disse værdier til en TypedAggregation-forespørgsel.
public List<FulfillmentChannel> getFulfillmentChannels(
String SOME_VARIABLE_STRING_1,
String SOME_VARIABLE_STRING_2) {
AggregationOperation match = Aggregation.match(
Criteria.where("dayOfWeek").is(SOME_VARIABLE_STRING_1));
AggregationOperation match2 = Aggregation.match(
Criteria.where("deliveryZipCodeTimings").ne(Collections.EMPTY_LIST));
String query =
"{ $lookup: { " +
"from: 'deliveryZipCodeTiming'," +
"let: { location_id: '$fulfillmentLocationId' }," +
"pipeline: [{" +
"$match: {$expr: {$and: [" +
"{ $eq: ['$fulfillmentLocationId', '$$location_id']}," +
"{ $eq: ['$zipCode', '" + SOME_VARIABLE_STRING_2 + "']}]}}}," +
"{ $project: { _id: 0, zipCode: 1, cutoffTime: 1 } }]," +
"as: 'deliveryZipCodeTimings'}}";
TypedAggregation<FulfillmentChannel> aggregation = Aggregation.newAggregation(
FulfillmentChannel.class,
match,
new CustomProjectAggregationOperation(query),
match2
);
AggregationResults<FulfillmentChannel> results =
mongoTemplate.aggregate(aggregation, FulfillmentChannel.class);
return results.getMappedResults();
}