Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2627

Accumulators not working properly

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.5.0, 3.6.0
    • Component/s: BSON
    • Environment:
      Windows 8.1 - IDE Eclipse Java - Java 8 - MongoDB 3.4.9

      Accumulators dosn't work as they should, they just replace the value given instead to process it.

      Example:

      Document document = new Document("firstname", "Pedro")
      .append("lastname", "Doe")
      .append("age", 14)
      .append("country", "Tanzania")
      .append("index", 1);

      collection.insertOne(document);

      List<Bson> query= asList(Aggregates.match(Filters.eq("firstname", "Pedro")),Aggregates.group("$_id", Accumulators.avg("age", 100), Accumulators.sum("index", 100)));
      AggregateIterable<Document> resuls t= collection.aggregate(query);
      for(Document d : results)

      { System.out.println(d.toJson()); }

      -Result:
      { "_id" :

      { "$oid" : "59dbb669dfbc63214831e70c" }

      , "age" : 100.0, "index" : 100 }

      -expected:
      { "_id" :

      { "$oid" : "59dbb669dfbc63214831e70c" }

      , "age" : 57.0, "index" : 101}

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            pendy01 ALESSANDRO PENDINELLI
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: