I searched in vain and now pose my question to the masses.
- I have a Collection of
GpsRecord, and eachGpsRecordbelongs to aTrackRecord - Each
GpsRecordholds anObjectIdreferring to its parentTrackRecord - I want to query the
GpsRecordcollection based on a list ofTrackRecord.ids
From this query I would like to return a List<List<GpsRecord>> from an aggregate query in MonogDB. My question is how do I correctly define the outputType parameter in .aggregate(agg, GpsRecord.class, List<List<GpsRecord>>)?
@Repository
public class GpsRepositoryImpl implements GpsRepositoryCustom {
private final MongoTemplate _mongoTemplate;
@Autowired
public GpsRepositoryImpl(MongoTemplate mongoTemplate) {
_mongoTemplate = mongoTemplate;
}
@Override
public List<List<GpsRecord>> aggregate(List<ObjectId> ids) {
MatchOperation match = getMatchOperation(ids);
GroupOperation group = getGroupOperation();
Aggregation agg = Aggregation.newAggregation(match, group);
return _mongoTemplate
.aggregate(agg, GpsRecord.class, List<List<GpsRecord>>)
.getMappedResults();
}
private MatchOperation getMatchOperation(List<ObjectId> ids) {
Criteria criteria = Criteria.where("trackRecord.id").in(ids);
return new MatchOperation(criteria);
}
private GroupOperation getGroupOperation() {
GroupOperation agg = Aggregation.group("trackRecord.id");
return agg;
}
}
Edit
Example of a GpsRecord
{
"_id": ObjectId("593d382c5b3ae715b2cac03d"),
"_class": "gps",
"location": {
"type": "Point",
"coordinates": [116.315148, 39.984538]
},
"dateTime": ISODate("2008-10-23T02:54:40Z"),
"trackRecord": DBRef("trackRecords", ObjectId("593d382b5b3ae715b2cac029"))
}
Example of a TrackRecord
{
"_id": ObjectId("593d382b5b3ae715b2cac029"),
"_class": "track",
"name": "20081117155223.plt",
"bbox": {
"type": "Polygon",
"coordinates": [[[116.31949,39.999686],[116.325796,39.999686],[116.325796,40.009678],[116.31949,40.009678],[116.31949,39.999686]]]
}
}
A TrackRecord consists of many GpsRecord objects, as in thousands of them or more.
So based on a List of TrackRecord._id I would like to return a List of List<GpsRecord>.
List<List<…>>from just callingMongoOperations.aggregate(…). Query the results and transform these into the representation you're supposed to return. - mp911deList<...>? - StevanList<…>- mp911de