spring-projects / spring-projects/spring-data-mongodb
Allow InBuilder creation from an array of values [DATAMONGO-2194]
@mp911de is already working on this.
Since Dec 30, 2020.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.