Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-4475

Aggregation tool generating Java code that causes runtime errors

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.26.0
    • Affects Version/s: 1.22.1
    • Component/s: Aggregation pipeline
    • Labels:
      None
    • Environment:
      node.js / npm versions: v12.12.0 / 6.13.4
      OS: OS X 10.15.7
      Java Driver : 4.0.5
    • Not Needed
    • Iteration Uglifruit

      I've built a pipeline in Compass that uses a project phase with $reduce:

      I have a project phase that also uses $reduce:

      {
        _id: 0,
        title: '$playlist.songs.title',
        artist: {
          $reduce: {
            input: '$playlist.songs.artists.name',
            initialValue: "",
            in: { $concat : ["$$value", " ", "$$this"] }
          }
        }
      }

      The pipeline executes fine in Compass and gives me back to documents I expect.

      However, when I export to Java driver code, the code that is generated results in a runtime error in my application.

      Here is the Java code that is generated is:

      project(
        fields(
            excludeId(), 
            computed("title", "$playlist.songs.title"), 
            computed("artist", 
              eq("$reduce", 
                and(
                  eq("input", "$playlist.songs.artists.name"),
                  eq("initialValue", ""), 
                  eq("in", eq("$concat", Arrays.asList("$$value", " ", "$$this"))))))))

      And the error that is returned:

      com.mongodb.MongoCommandException: Command failed with error 40076 (Location40076): '$reduce found an unknown argument: $and'

      As some background, this was a pipeline I generated over a year ago (not sure the precise Compass version) and it worked fine with Java driver 3.x and Server 3.x. A few months ago the server was upgraded to 4.x, and the pipeline continued to run fine using Java driver 3.x.

      It wasn't until I upgraded the Java driver to 4.x that this issue came up.

      I have rebuilt the pipeline in the latest Compass version, and confirmed it still generates the same snippet of Java code that results in the error.

            Assignee:
            michael.rose@mongodb.com Michael Rose (Inactive)
            Reporter:
            prattm@gmail.com Michael Pratt
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: