diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/StringOperators.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/StringOperators.java
index 5a31f6b3fc..710c6c855e 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/StringOperators.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/StringOperators.java
@@ -515,6 +515,120 @@ public RTrim rtrim(AggregationExpression expression) {
private RTrim createRTrim() {
return usesFieldRef() ? RTrim.valueOf(fieldReference) : RTrim.valueOf(expression);
}
+
+ /**
+ * Creates new {@link AggregationExpression} that takes the associated string representation and applies the given
+ * regular expression to find the document with the first match.
+ * NOTE: Requires MongoDB 4.0 or later.
+ *
+ * @return new instance of {@link RegexFind}.
+ */
+ public RegexFind regexFind(String regex) {
+ return createRegexFind().regex(regex);
+ }
+
+ /**
+ * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular
+ * expression resulting from the given {@link AggregationExpression} to find the document with the first match.
+ * NOTE: Requires MongoDB 4.0 or later.
+ *
+ * @return new instance of {@link RegexFind}.
+ */
+ public RegexFind regexFind(AggregationExpression expression) {
+ return createRegexFind().regexOf(expression);
+ }
+
+ /**
+ * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular
+ * expression with the options specified in the argument to find the document with the first match.
+ *
+ * @param regex the regular expression to apply
+ * @param options the options to use
+ * @return new instance of {@link RegexFind}.
+ */
+ public RegexFind regexFind(String regex,String options) {
+ return createRegexFind().regex(regex).options(options);
+ }
+
+ private RegexFind createRegexFind() {
+ return usesFieldRef() ? RegexFind.valueOf(fieldReference) : RegexFind.valueOf(expression);
+ }
+
+ /**
+ * Creates new {@link AggregationExpression} that takes the associated string representation and applies the given
+ * regular expression to find all the documents with the match.
+ * NOTE: Requires MongoDB 4.0 or later.
+ *
+ * @return new instance of {@link RegexFindAll}.
+ */
+ public RegexFindAll regexFindAll(String regex) {
+ return createRegexFindAll().regex(regex);
+ }
+
+ /**
+ * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular
+ * expression resulting from the given {@link AggregationExpression} to find all the documents with the match..
+ * NOTE: Requires MongoDB 4.0 or later.
+ *
+ * @return new instance of {@link RegexFindAll}.
+ */
+ public RegexFindAll regexFindAll(AggregationExpression expression) {
+ return createRegexFindAll().regexOf(expression);
+ }
+
+ /**
+ * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular
+ * expression with the options specified in the argument to find all the documents with the match..
+ *
+ * @param regex the regular expression to apply
+ * @param options the options to use
+ * @return new instance of {@link RegexFindAll}.
+ */
+ public RegexFindAll regexFindAll(String regex,String options) {
+ return createRegexFindAll().regex(regex).options(options);
+ }
+
+ private RegexFindAll createRegexFindAll() {
+ return usesFieldRef() ? RegexFindAll.valueOf(fieldReference) : RegexFindAll.valueOf(expression);
+ }
+
+ /**
+ * Creates new {@link AggregationExpression} that takes the associated string representation and applies the given
+ * regular expression to find if a match is found or not.
+ * NOTE: Requires MongoDB 4.0 or later.
+ *
+ * @return new instance of {@link RegexMatch}.
+ */
+ public RegexMatch regexMatch(String regex) {
+ return createRegexMatch().regex(regex);
+ }
+
+ /**
+ * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular
+ * expression resulting from the given {@link AggregationExpression} to find if a match is found or not.
+ * NOTE: Requires MongoDB 4.0 or later.
+ *
+ * @return new instance of {@link RegexMatch}.
+ */
+ public RegexMatch regexMatch(AggregationExpression expression) {
+ return createRegexMatch().regexOf(expression);
+ }
+
+ /**
+ * Creates new {@link AggregationExpression} that takes the associated string representation and applies the regular
+ * expression with the options specified in the argument to find if a match is found or not.
+ *
+ * @param regex the regular expression to apply
+ * @param options the options to use
+ * @return new instance of {@link RegexMatch}.
+ */
+ public RegexMatch regexMatch(String regex,String options) {
+ return createRegexMatch().regex(regex).options(options);
+ }
+
+ private RegexMatch createRegexMatch() {
+ return usesFieldRef() ? RegexMatch.valueOf(fieldReference) : RegexMatch.valueOf(expression);
+ }
private boolean usesFieldRef() {
return fieldReference != null;
@@ -1477,4 +1591,328 @@ protected String getMongoMethod() {
return "$rtrim";
}
}
+
+ /**
+ * {@link AggregationExpression} for {@code $regexFind} which applies a regular expression (regex) to a string and
+ * returns information on the first matched substring.
+ * NOTE: Requires MongoDB 4.0 or later.
+ *
+ */
+ public static class RegexFind extends AbstractAggregationExpression {
+
+ protected RegexFind(Object value) {
+ super(value);
+ }
+
+ @Override
+ protected String getMongoMethod() {
+ return "$regexFind";
+ }
+
+ /**
+ * Creates new {@link RegexFind} using the value of the provided {@link Field fieldReference} as {@literal input} value.
+ *
+ * @param fieldReference must not be {@literal null}.
+ * @return new instance of {@link RegexFind}.
+ */
+ public static RegexFind valueOf(String fieldReference) {
+ Assert.notNull(fieldReference, "FieldReference must not be null!");
+ return new RegexFind(Collections.singletonMap("input", Fields.field(fieldReference)));
+ }
+
+ /**
+ * Creates new {@link RegexFind} using the result of the provided {@link AggregationExpression} as {@literal input}
+ * value.
+ *
+ * @param expression must not be {@literal null}.
+ * @return new instance of {@link RegexFind}.
+ */
+ public static RegexFind valueOf(AggregationExpression expression) {
+ Assert.notNull(expression, "Expression must not be null!");
+ return new RegexFind(Collections.singletonMap("input", expression));
+ }
+
+ /**
+ * Optional specify the options to use with the regular expression.
+ *
+ * @param options must not be {@literal null}.
+ * @return new instance of {@link RegexFind}.
+ */
+ public RegexFind options(String options) {
+ Assert.notNull(options, "Options must not be null!");
+ return new RegexFind(append("options", options));
+ }
+
+ /**
+ * Optional specify the reference to the {@link Field field} holding the options values to use with the regular expression.
+ *
+ * @param fieldReference must not be {@literal null}.
+ * @return new instance of {@link RegexFind}.
+ */
+ public RegexFind optionsOf(String fieldReference) {
+ Assert.notNull(fieldReference, "FieldReference must not be null!");
+ return new RegexFind(append("options", Fields.field(fieldReference)));
+ }
+
+ /**
+ * Optional specify the {@link AggregationExpression} evaluating to the options values to use with the regular expression.
+ *
+ * @param expression must not be {@literal null}.
+ * @return new instance of {@link RegexFind}.
+ */
+ public RegexFind optionsOf(AggregationExpression expression) {
+ Assert.notNull(expression, "Expression must not be null!");
+ return new RegexFind(append("options", expression));
+ }
+
+ /**
+ * Optional specify the regular expression to apply.
+ *
+ * @param regex must not be {@literal null}.
+ * @return new instance of {@link RegexFind}.
+ */
+ public RegexFind regex(String regex) {
+ Assert.notNull(regex, "Regex must not be null!");
+ return new RegexFind(append("regex",regex));
+ }
+
+ /**
+ * Optional specify the reference to the {@link Field field} holding the regular expression to apply.
+ *
+ * @param fieldReference must not be {@literal null}.
+ * @return new instance of {@link RegexFind}.
+ */
+ public RegexFind regexOf(String fieldReference) {
+ Assert.notNull(fieldReference, "fieldReference must not be null!");
+ return new RegexFind(append("regex",Fields.field(fieldReference)));
+ }
+
+ /**
+ * Optional specify the {@link AggregationExpression} evaluating to the regular expression to apply.
+ *
+ * @param expression must not be {@literal null}.
+ * @return new instance of {@link RegexFind}.
+ */
+ public RegexFind regexOf(AggregationExpression expression) {
+ Assert.notNull(expression, "Expression must not be null!");
+ return new RegexFind(append("regex",expression));
+ }
+
+ }
+
+ /**
+ * {@link AggregationExpression} for {@code $regexFindAll} which applies a regular expression (regex) to a string and
+ * returns information on all the matched substrings.
+ * NOTE: Requires MongoDB 4.0 or later.
+ *
+ */
+ public static class RegexFindAll extends AbstractAggregationExpression {
+
+ protected RegexFindAll(Object value) {
+ super(value);
+ }
+
+ @Override
+ protected String getMongoMethod() {
+ return "$regexFindAll";
+ }
+
+ /**
+ * Creates new {@link RegexFindAll} using the value of the provided {@link Field fieldReference} as {@literal input} value.
+ *
+ * @param fieldReference must not be {@literal null}.
+ * @return new instance of {@link RegexFindAll}.
+ */
+ public static RegexFindAll valueOf(String fieldReference) {
+ Assert.notNull(fieldReference, "FieldReference must not be null!");
+ return new RegexFindAll(Collections.singletonMap("input", Fields.field(fieldReference)));
+ }
+
+ /**
+ * Creates new {@link RegexFindAll} using the result of the provided {@link AggregationExpression} as {@literal input}
+ * value.
+ *
+ * @param expression must not be {@literal null}.
+ * @return new instance of {@link RegexFindAll}.
+ */
+ public static RegexFindAll valueOf(AggregationExpression expression) {
+ Assert.notNull(expression, "Expression must not be null!");
+ return new RegexFindAll(Collections.singletonMap("input", expression));
+ }
+
+ /**
+ * Optional specify the options to use with the regular expression.
+ *
+ * @param options must not be {@literal null}.
+ * @return new instance of {@link RegexFindAll}.
+ */
+ public RegexFindAll options(String options) {
+ Assert.notNull(options, "Options must not be null!");
+ return new RegexFindAll(append("options", options));
+ }
+
+ /**
+ * Optional specify the reference to the {@link Field field} holding the options values to use with the regular expression.
+ *
+ * @param fieldReference must not be {@literal null}.
+ * @return new instance of {@link RegexFindAll}.
+ */
+ public RegexFindAll optionsOf(String fieldReference) {
+ Assert.notNull(fieldReference, "fieldReference must not be null!");
+ return new RegexFindAll(append("options", Fields.field(fieldReference)));
+ }
+
+ /**
+ * Optional specify the {@link AggregationExpression} evaluating to the options values to use with the regular expression.
+ *
+ * @param expression must not be {@literal null}.
+ * @return new instance of {@link RegexFindAll}.
+ */
+ public RegexFindAll optionsOf(AggregationExpression expression) {
+ Assert.notNull(expression, "Expression must not be null!");
+ return new RegexFindAll(append("options", expression));
+ }
+
+ /**
+ * Optional specify the regular expression to apply.
+ *
+ * @param regex must not be {@literal null}.
+ * @return new instance of {@link RegexFindAll}.
+ */
+ public RegexFindAll regex(String regex) {
+ Assert.notNull(regex, "Regex must not be null!");
+ return new RegexFindAll(append("regex",regex));
+ }
+
+ /**
+ * Optional specify the reference to the {@link Field field} holding the regular expression to apply.
+ *
+ * @param fieldReference must not be {@literal null}.
+ * @return new instance of {@link RegexFindAll}.
+ */
+ public RegexFindAll regexOf(String fieldReference) {
+ Assert.notNull(fieldReference, "fieldReference must not be null!");
+ return new RegexFindAll(append("regex",Fields.field(fieldReference)));
+ }
+
+ /**
+ * Optional specify the {@link AggregationExpression} evaluating to the regular expression to apply.
+ *
+ * @param expression must not be {@literal null}.
+ * @return new instance of {@link RegexFindAll}.
+ */
+ public RegexFindAll regexOf(AggregationExpression expression) {
+ Assert.notNull(expression, "Expression must not be null!");
+ return new RegexFindAll(append("regex",expression));
+ }
+
+ }
+
+ /**
+ * {@link AggregationExpression} for {@code $regexMatch} which applies a regular expression (regex) to a string and
+ * returns a boolean that indicates if a match is found or not.
+ * NOTE: Requires MongoDB 4.0 or later.
+ *
+ */
+ public static class RegexMatch extends AbstractAggregationExpression {
+
+ protected RegexMatch(Object value) {
+ super(value);
+ }
+
+ @Override
+ protected String getMongoMethod() {
+ return "$regexMatch";
+ }
+
+ /**
+ * Creates new {@link RegexMatch} using the value of the provided {@link Field fieldReference} as {@literal input} value.
+ *
+ * @param fieldReference must not be {@literal null}.
+ * @return new instance of {@link RegexMatch}.
+ */
+ public static RegexMatch valueOf(String fieldReference) {
+ Assert.notNull(fieldReference, "FieldReference must not be null!");
+ return new RegexMatch(Collections.singletonMap("input", Fields.field(fieldReference)));
+ }
+
+ /**
+ * Creates new {@link RegexMatch} using the result of the provided {@link AggregationExpression} as {@literal input}
+ * value.
+ *
+ * @param expression must not be {@literal null}.
+ * @return new instance of {@link RegexMatch}.
+ */
+ public static RegexMatch valueOf(AggregationExpression expression) {
+ Assert.notNull(expression, "Expression must not be null!");
+ return new RegexMatch(Collections.singletonMap("input", expression));
+ }
+
+ /**
+ * Optional specify the options to use with the regular expression.
+ *
+ * @param options must not be {@literal null}.
+ * @return new instance of {@link RegexMatch}.
+ */
+ public RegexMatch options(String options) {
+ Assert.notNull(options, "Options must not be null!");
+ return new RegexMatch(append("options", options));
+ }
+
+ /**
+ * Optional specify the reference to the {@link Field field} holding the options values to use with the regular expression.
+ *
+ * @param fieldReference must not be {@literal null}.
+ * @return new instance of {@link RegexMatch}.
+ */
+ public RegexMatch optionsOf(String fieldReference) {
+ Assert.notNull(fieldReference, "FieldReference must not be null!");
+ return new RegexMatch(append("options", Fields.field(fieldReference)));
+ }
+
+ /**
+ * Optional specify the {@link AggregationExpression} evaluating to the options values to use with the regular expression.
+ *
+ * @param expression must not be {@literal null}.
+ * @return new instance of {@link RegexMatch}.
+ */
+ public RegexMatch optionsOf(AggregationExpression expression) {
+ Assert.notNull(expression, "Expression must not be null!");
+ return new RegexMatch(append("options", expression));
+ }
+
+ /**
+ * Optional specify the regular expression to apply.
+ *
+ * @param regex must not be {@literal null}.
+ * @return new instance of {@link RegexMatch}.
+ */
+ public RegexMatch regex(String regex) {
+ Assert.notNull(regex, "Regex must not be null!");
+ return new RegexMatch(append("regex",regex));
+ }
+
+ /**
+ * Optional specify the reference to the {@link Field field} holding the regular expression to apply.
+ *
+ * @param fieldReference must not be {@literal null}.
+ * @return new instance of {@link RegexMatch}.
+ */
+ public RegexMatch regexOf(String fieldReference) {
+ Assert.notNull(fieldReference, "FieldReference must not be null!");
+ return new RegexMatch(append("regex",Fields.field(fieldReference)));
+ }
+
+ /**
+ * Optional specify the {@link AggregationExpression} evaluating to the regular expression to apply.
+ *
+ * @param expression must not be {@literal null}.
+ * @return new instance of {@link RegexMatch}.
+ */
+ public RegexMatch regexOf(AggregationExpression expression) {
+ Assert.notNull(expression, "Expression must not be null!");
+ return new RegexMatch(append("regex",expression));
+ }
+
+ }
}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/MethodReferenceNode.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/MethodReferenceNode.java
index 5a2c48bc20..67cbefe8cf 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/MethodReferenceNode.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/MethodReferenceNode.java
@@ -101,6 +101,9 @@ public class MethodReferenceNode extends ExpressionNode {
map.put("trim", mapArgRef().forOperator("$trim").mappingParametersTo("input", "chars"));
map.put("ltrim", mapArgRef().forOperator("$ltrim").mappingParametersTo("input", "chars"));
map.put("rtrim", mapArgRef().forOperator("$rtrim").mappingParametersTo("input", "chars"));
+ map.put("regexFind", mapArgRef().forOperator("$regexFind").mappingParametersTo("input", "regex" , "options"));
+ map.put("regexFindAll", mapArgRef().forOperator("$regexFindAll").mappingParametersTo("input", "regex" , "options"));
+ map.put("regexMatch", mapArgRef().forOperator("$regexMatch").mappingParametersTo("input", "regex" , "options"));
// TEXT SEARCH OPERATORS
map.put("meta", singleArgRef().forOperator("$meta"));
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java
index 805fc10f38..ff6771d9f1 100755
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java
@@ -1766,6 +1766,33 @@ public void shouldRenderSubstrCPCorrectly() {
assertThat(agg)
.isEqualTo(Document.parse("{ $project : { yearSubstring: { $substrCP: [ \"$quarter\", 0, 2 ] } } }"));
}
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFindCorrectly() {
+
+ Document agg = project().and(StringOperators.valueOf("field1").regexFind("e")).as("regex")
+ .toDocument(Aggregation.DEFAULT_CONTEXT);
+
+ assertThat(agg).isEqualTo(Document.parse("{ $project : { regex: { $regexFind: { \"input\" : \"$field1\", \"regex\" : \"e\" } } } }"));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFindAllCorrectly() {
+
+ Document agg = project().and(StringOperators.valueOf("field1").regexFindAll("e")).as("regex")
+ .toDocument(Aggregation.DEFAULT_CONTEXT);
+
+ assertThat(agg).isEqualTo(Document.parse("{ $project : { regex: { $regexFindAll: { \"input\" : \"$field1\", \"regex\" : \"e\" } } } }"));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexMatchCorrectly() {
+
+ Document agg = project().and(StringOperators.valueOf("field1").regexMatch("e")).as("regex")
+ .toDocument(Aggregation.DEFAULT_CONTEXT);
+
+ assertThat(agg).isEqualTo(Document.parse("{ $project : { regex: { $regexMatch: { \"input\" : \"$field1\", \"regex\" : \"e\" } } } }"));
+ }
@Test // DATAMONGO-1548
public void shouldRenderIndexOfArrayCorrectly() {
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java
index b67beed126..01e0c2df41 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java
@@ -805,6 +805,70 @@ public void shouldRenderRtrimWithCharsFromFieldReference() {
assertThat(transform("rtrim(field1, field2)"))
.isEqualTo(Document.parse("{ \"$rtrim\" : {\"input\" : \"$field1\", \"chars\" : \"$field2\" }}"));
}
+
+ @Test // DATAMONGO-3725
+ public void shouldRenderRegexFindWithoutOptions() {
+
+ assertThat(transform("regexFind(field1,'e')"))
+ .isEqualTo(Document.parse("{ \"$regexFind\" : {\"input\" : \"$field1\" , \"regex\" : \"e\"}}"));
+ }
+
+ @Test // DATAMONGO-3725
+ public void shouldRenderRegexFindWithOptions() {
+
+ assertThat(transform("regexFind(field1,'e','i')"))
+ .isEqualTo(Document.parse("{ \"$regexFind\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"i\"}}"));
+ }
+
+ @Test // DATAMONGO-3725
+ public void shouldRenderRegexFindWithOptionsFromFieldReference() {
+
+ assertThat(transform("regexFind(field1,'e',field2)"))
+ .isEqualTo(Document.parse("{ \"$regexFind\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"$field2\"}}"));
+ }
+
+ @Test // DATAMONGO-3725
+ public void shouldRenderRegexFindAllWithoutOptions() {
+
+ assertThat(transform("regexFindAll(field1,'e')"))
+ .isEqualTo(Document.parse("{ \"$regexFindAll\" : {\"input\" : \"$field1\" , \"regex\" : \"e\"}}"));
+ }
+
+ @Test // DATAMONGO-3725
+ public void shouldRenderRegexFindAllWithOptions() {
+
+ assertThat(transform("regexFindAll(field1,'e','i')"))
+ .isEqualTo(Document.parse("{ \"$regexFindAll\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"i\"}}"));
+ }
+
+ @Test // DATAMONGO-3725
+ public void shouldRenderRegexFindAllWithOptionsFromFieldReference() {
+
+ assertThat(transform("regexFindAll(field1,'e',field2)"))
+ .isEqualTo(Document.parse("{ \"$regexFindAll\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"$field2\"}}"));
+ }
+
+ @Test // DATAMONGO-3725
+ public void shouldRenderRegexMatchWithoutOptions() {
+
+ assertThat(transform("regexMatch(field1,'e')"))
+ .isEqualTo(Document.parse("{ \"$regexMatch\" : {\"input\" : \"$field1\" , \"regex\" : \"e\"}}"));
+ }
+
+ @Test // DATAMONGO-3725
+ public void shouldRenderRegexMatchWithOptions() {
+
+ assertThat(transform("regexMatch(field1,'e','i')"))
+ .isEqualTo(Document.parse("{ \"$regexMatch\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"i\"}}"));
+ }
+
+ @Test // DATAMONGO-3725
+ public void shouldRenderRegexMatchWithOptionsFromFieldReference() {
+
+ assertThat(transform("regexMatch(field1,'e',field2)"))
+ .isEqualTo(Document.parse("{ \"$regexMatch\" : {\"input\" : \"$field1\" , \"regex\" : \"e\" , \"options\" : \"$field2\"}}"));
+ }
+
@Test // DATAMONGO-2077
public void shouldRenderConvertWithoutOptionalParameters() {
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/StringOperatorsUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/StringOperatorsUnitTests.java
index 0dbe362ae4..cdd0b38dbc 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/StringOperatorsUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/StringOperatorsUnitTests.java
@@ -144,5 +144,111 @@ public void shouldRenderRTrimWithCharsExpression() {
assertThat(StringOperators.valueOf("shrewd").rtrim(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT))
.isEqualTo(Document.parse("{ $rtrim: { \"input\" : \"$shrewd\", \"chars\" : " + EXPRESSION_STRING + " } } "));
}
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFindAll() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexFindAll("e").toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexFindAll: { \"input\" : \"$shrewd\" , \"regex\" : \"e\" } }"));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFindAllForExpression() {
+
+ assertThat(StringOperators.valueOf(EXPRESSION).regexFindAll("e").toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexFindAll: { \"input\" : " + EXPRESSION_STRING + " , \"regex\" : \"e\" } } "));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFindAllForRegexExpression() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexFindAll(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexFindAll: { \"input\" : \"$shrewd\" , \"regex\" : " + EXPRESSION_STRING + " } } "));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFindAllWithOptions() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexFindAll("e").options("i").toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexFindAll: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : \"i\" } } "));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFindAllWithOptionsExpression() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexFindAll("e").optionsOf(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexFindAll: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : " + EXPRESSION_STRING + " } } "));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexMatch() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexMatch("e").toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexMatch: { \"input\" : \"$shrewd\" , \"regex\" : \"e\" } }"));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexMatchForExpression() {
+
+ assertThat(StringOperators.valueOf(EXPRESSION).regexMatch("e").toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexMatch: { \"input\" : " + EXPRESSION_STRING + " , \"regex\" : \"e\" } } "));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexMatchForRegexExpression() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexMatch(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexMatch: { \"input\" : \"$shrewd\" , \"regex\" : " + EXPRESSION_STRING + " } } "));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexMatchWithOptions() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexMatch("e").options("i").toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexMatch: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : \"i\" } } "));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexMatchWithOptionsExpression() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexMatch("e").optionsOf(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexMatch: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : " + EXPRESSION_STRING + " } } "));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFind() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexFind("e").toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexFind: { \"input\" : \"$shrewd\" , \"regex\" : \"e\" } }"));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFindForExpression() {
+
+ assertThat(StringOperators.valueOf(EXPRESSION).regexFind("e").toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexFind: { \"input\" : " + EXPRESSION_STRING + " , \"regex\" : \"e\" } } "));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFindForRegexExpression() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexFind(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexFind: { \"input\" : \"$shrewd\" , \"regex\" : " + EXPRESSION_STRING + " } } "));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFindWithOptions() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexFind("e").options("i").toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexFind: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : \"i\" } } "));
+ }
+
+ @Test // DATAMONGO - 3725
+ public void shouldRenderRegexFindWithOptionsExpression() {
+
+ assertThat(StringOperators.valueOf("shrewd").regexFind("e").optionsOf(EXPRESSION).toDocument(Aggregation.DEFAULT_CONTEXT))
+ .isEqualTo(Document.parse("{ $regexFind: { \"input\" : \"$shrewd\", \"regex\" : \"e\" , \"options\" : " + EXPRESSION_STRING + " } } "));
+ }
+
}