Skip to content

Allow InBuilder creation from an array of values [DATAMONGO-2194] #3056

Open
@spring-projects-issues

Description

@spring-projects-issues

poiu77 opened DATAMONGO-2194 and commented

Hi.

When i try to use operator In from ArrayOperations in filter aggregation builder like this:

Aggregation aggregation = newAggregation(
        project().and(filter("items")
                .as("item")
                .by(arrayOf("item.id").containsValue(Arrays.asList("1", "2"))))
                .as("items"));

 then get error:

$in requires an array as a second argument

I am able to show generated aggregation command: 

{
  "$project": {
    "items": {
      "$filter": {
        "input": "$items",
        "as": "item",
        "cond": {
          "$in": [
            [ "1", "2" ],
            "$$item.id"
          ]
        }
      }
    }
  }
}

And I see the problem. It is connected with ordering of elements $$item.id and table in element $in. According to mongo documentation example here it should looks like this:

...
  "cond": {
    "$in": [
      "$$item.id",
      [ "1", "2" ]
    ]
  }
...

I believe the simple solution is to change this line (and other connected with this problem) to 

return new In(Arrays.asList(Fields.field(fieldReference), value));

Best regards, Darek.

 


Affects: 2.1.4 (Lovelace SR4)

1 votes, 3 watchers

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions