Accumulators not working properly

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: 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
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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 Lawley
              Reporter:
              ALESSANDRO PENDINELLI
              None
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: