Skip to content

DATAMONGO-2287: Adding Support for Array Aggregate In #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Shashank Sharma
* @since 1.0
*/
public class ArrayOperators {
Expand Down Expand Up @@ -1496,6 +1497,29 @@ public In containsValue(Object value) {
};
}

/**
* Support for Aggregation In
* Search an Element in List of Objects to Filter
* Start creating {@link In}.
* @author Shashank Sharma
* @param elementList must not be {@literal null}.
* @return
*/
public static InBuilder arrayOf(final List<Object> elementList) {

Assert.notNull(elementList, "Elements must not be null!");

return new InBuilder() {

@Override
public In containsValue(Object value) {

Assert.notNull(value, "Value must not be null!");
return new In(Arrays.asList(value, elementList));
}
};
}

/**
* @author Christoph Strobl
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ public void toArrayWithArgumentList() {
assertThat(ArrayToObject.arrayToObject(source).toDocument(Aggregation.DEFAULT_CONTEXT))
.isEqualTo(Document.parse("{ $arrayToObject: [ [ \"king\", \"shrewd\"], [ \"prince\", \"verity\" ] ] } "));
}

@Test // DATAMONGO-2287
public void inArrayAggregationWithArgumentList() {

assertThat(ArrayOperators.In.arrayOf(Arrays.asList("Shashank", "Sharma"))
.containsValue("$userName").toDocument(Aggregation.DEFAULT_CONTEXT))
.isEqualTo(Document.parse("{ \"$in\" : [\"$userName\", [\"Shashank\", \"Sharma\"]] }"));
}
}