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

aggregate functions, not do match correctly

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: API
    • None

      with this code bellow: 

      mongoTemplate.getCollection(COLLECTION_NAME).aggregate(
      Arrays.asList(

      Aggregates.match(Filters.eq("cpfCnpj",cpfCnpj))
      ,
      Aggregates.group(
      new Document()
      .append("cpfCnpj", "$cpfCnpj")
      .append("namPostalArea", "$namPostalArea")
      .append("namDistrict", "$namDistrict")
      .append("namFederationUnit", "$namFederationUnit")
      .append("namCity", "$namCity")
      .append("quantity", "$quantity")
      )
      ,
      Aggregates.group(
      new Document().append("cpfCnpj", "$_id.cpfCnpj")
      ,Accumulators.sum("totalDistinctAddresses", "$_id.quantity")
      )
      ,
      Aggregates.project(
      Projections.fields(
      Projections.excludeId(),
      Projections.computed("cpfCnpj", "$_id.cpfCnpj"),
      Projections.include("totalDistinctAddresses")
      )
      )
      ,
      Aggregates.merge(VIEW_NAME, new MergeOptions()
      .uniqueIdentifier("cpfCnpj")
      .whenNotMatched(MergeOptions.WhenNotMatched.INSERT)
      .whenMatchedPipeline(
      Arrays.asList(new Document()
      .append("$addFields", new Document()
      .append("totalDistinctAddresses", new Document("$add", Arrays.asList("$totalDistinctAddresses", "$$new.totalDistinctAddresses")))
      )
      )
      )
      )
      )
      )

       

      if has only one cpfCnpj in the collection,  it is doing aggregation for 113 items of the collection, the final result is correctly, but with match stage and contain only one of the cpf used, should do only one aggregation.

       

      The driver version is 4.0.3

       

      the data used in the log are fake , so not contain sensitive data

       

      I attached the log event, the first log event is the query used in match stage.

       

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            rodrigobrito.ciencia@gmail.com rodrigo brito
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: