I am using Jongo to query my MongoDB with Java. My question is "How can I save a sum into a Class attribute?"
I have a Class OffersByPostalCode
public class OffersByPostalCode {
private String _id;
private String offers;
public OffersByPostalCode(String _id, String offers) {
this._id = _id;
this.offers = offers;
//Getters, setters & toString are here
}
SO, I'am trying to query my DB and get Offers group by postalCode Using Jongo, here is the query :
list_job = collection.aggregate("{$group:{ _id :'$postalCode',offers:{'$sum':1}}}).as(OffersByPostalCode.class);
The problem is that when I get my result from the query I have my postalCode but the offers attribute which is the sum of offers by postalCode is always NULL. It works fine in MongoDB shell.