1

Given the following collection:

{"city" : {
        "name" : "BLUMENAU",
        "state" : {
            "country" : {
                "latitude" : 0.0,
                "longitude" : 0.0
            },
            "latitude" : -27.2423392,
            "longitude" : -50.2188556
        },
        "latitude" : -26.91610771,
        "longitude" : -49.05763088,
        "_id" : "570c0bd2e375c64456a23e73"
    }
}

and the following class:

class City{
    @MongoId
    private Object id;
    private String name;
    private State state;
    private double latitude;
    private double longitude;
}

I was wondering if I could an aggregated query to retrieve the cout of these cities as well as all the information about the root collection (city) and expect that jongo return the response inside an City object. Something like the following mongo shell query:

db.someCollection.aggregate([
    {$group: {_id: '$city', 'count': {$sum: 1}}},
    {$sort: {'count': -1}}
]);

I'd expect this: ResultsIterator<City> where the id attribute (Object) would be the City (with all the attributes setted, including the object State and it's attributes).

From all I can see using

org.jongo.MongoCollection.aggregate("   {$group: {_id: '$city', 'count': {$sum: 1}}},
    {$sort: {'count': -1}}").as(City.class);

I see a LinkedHashMap<K, V> in the id attributed and not a city object.

Cœur
  • 37,241
  • 25
  • 195
  • 267

0 Answers0