0

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.

Josh Gagnon
  • 5,342
  • 3
  • 26
  • 36
Alaa-GI
  • 410
  • 1
  • 5
  • 19

1 Answers1

0

Did you try

`list_job = collection.aggregate("{$group:{ _id :'$postalCode',offers:{$sum:1}}}).as(OffersByPostalCode.class);`
iMysak
  • 2,170
  • 1
  • 22
  • 35