diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AbstractAggregationExpression.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AbstractAggregationExpression.java
index 15092d670..bb46ee395 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AbstractAggregationExpression.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AbstractAggregationExpression.java
@@ -24,7 +24,6 @@ import java.util.List;
import java.util.Map;
import org.bson.Document;
-import org.springframework.data.mongodb.core.aggregation.Aggregation.SystemVariable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java
index 89d769066..ebee95678 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java
@@ -35,7 +35,6 @@ import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
import org.springframework.data.mongodb.core.query.NearQuery;
import org.springframework.data.mongodb.core.query.SerializationUtils;
-import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -766,48 +765,4 @@ public class Aggregation {
public String toString() {
return SerializationUtils.serializeToJsonSafely(toDocument("__collection__", DEFAULT_CONTEXT));
}
-
- /**
- * Describes the system variables available in MongoDB aggregation framework pipeline expressions.
- *
- * @author Thomas Darimont
- * @author Christoph Strobl
- * @see Aggregation Variables.
- */
- enum SystemVariable {
-
- ROOT, CURRENT, REMOVE;
-
- private static final String PREFIX = "$$";
-
- /**
- * Return {@literal true} if the given {@code fieldRef} denotes a well-known system variable, {@literal false}
- * otherwise.
- *
- * @param fieldRef may be {@literal null}.
- * @return {@literal true} if the given field refers to a {@link SystemVariable}.
- */
- public static boolean isReferingToSystemVariable(@Nullable String fieldRef) {
-
- if (fieldRef == null || !fieldRef.startsWith(PREFIX) || fieldRef.length() <= 2) {
- return false;
- }
-
- int indexOfFirstDot = fieldRef.indexOf('.');
- String candidate = fieldRef.substring(2, indexOfFirstDot == -1 ? fieldRef.length() : indexOfFirstDot);
-
- for (SystemVariable value : values()) {
- if (value.name().equals(candidate)) {
- return true;
- }
- }
-
- return false;
- }
-
- @Override
- public String toString() {
- return PREFIX.concat(name());
- }
- }
}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java
index 6478e3ec8..500863a0a 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Fields.java
@@ -245,7 +245,7 @@ public final class Fields implements Iterable {
private static String cleanUp(String source) {
- if (Aggregation.SystemVariable.isReferingToSystemVariable(source)) {
+ if (SystemVariable.isReferingToSystemVariable(source)) {
return source;
}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GroupOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GroupOperation.java
index 4773028c1..d7a8887f3 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GroupOperation.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GroupOperation.java
@@ -510,7 +510,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
return value;
}
- if (Aggregation.SystemVariable.isReferingToSystemVariable(reference)) {
+ if (SystemVariable.isReferingToSystemVariable(reference)) {
return reference;
}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java
index 07fcfe3d2..6d96e51c9 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperation.java
@@ -1395,7 +1395,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
// implicit reference or explicit include?
if (value == null || Boolean.TRUE.equals(value)) {
- if (Aggregation.SystemVariable.isReferingToSystemVariable(field.getTarget())) {
+ if (SystemVariable.isReferingToSystemVariable(field.getTarget())) {
return field.getTarget();
}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SystemVariable.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SystemVariable.java
new file mode 100644
index 000000000..524d23926
--- /dev/null
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SystemVariable.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2022 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.mongodb.core.aggregation;
+
+import org.springframework.lang.Nullable;
+
+/**
+ * Describes the system variables available in MongoDB aggregation framework pipeline expressions.
+ *
+ * @author Thomas Darimont
+ * @author Christoph Strobl
+ * @see Aggregation Variables.
+ */
+public enum SystemVariable {
+
+ /**
+ * Variable for the current datetime.
+ *
+ * @since 4.0
+ */
+ NOW,
+
+ /**
+ * Variable for the current timestamp.
+ *
+ * @since 4.0
+ */
+ CLUSTER_TIME,
+
+ /**
+ * Variable that references the root document.
+ */
+ ROOT,
+
+ /**
+ * Variable that references the start of the field path being processed.
+ */
+ CURRENT,
+
+ /**
+ * Variable that evaluates to a missing value.
+ */
+ REMOVE,
+
+ /**
+ * One of the allowed results of a {@literal $redact} expression
+ *
+ * @since 4.0
+ */
+ DESCEND,
+
+ /**
+ * One of the allowed results of a {@literal $redact} expression
+ *
+ * @since 4.0
+ */
+ PRUNE,
+ /**
+ * One of the allowed results of a {@literal $redact} expression
+ *
+ * @since 4.0
+ */
+ KEEP,
+
+ /**
+ * A variable that stores the metadata results of an Atlas Search query.
+ *
+ * @since 4.0
+ */
+ SEARCH_META;
+
+ private static final String PREFIX = "$$";
+
+ /**
+ * Return {@literal true} if the given {@code fieldRef} denotes a well-known system variable, {@literal false}
+ * otherwise.
+ *
+ * @param fieldRef may be {@literal null}.
+ * @return {@literal true} if the given field refers to a {@link SystemVariable}.
+ */
+ public static boolean isReferingToSystemVariable(@Nullable String fieldRef) {
+
+ if (fieldRef == null || !fieldRef.startsWith(PREFIX) || fieldRef.length() <= 2) {
+ return false;
+ }
+
+ int indexOfFirstDot = fieldRef.indexOf('.');
+ String candidate = fieldRef.substring(2, indexOfFirstDot == -1 ? fieldRef.length() : indexOfFirstDot);
+
+ for (SystemVariable value : values()) {
+ if (value.name().equals(candidate)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return PREFIX.concat(name());
+ }
+}
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ObjectOperatorsUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ObjectOperatorsUnitTests.java
index 1c26ec6cd..f8f94f888 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ObjectOperatorsUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ObjectOperatorsUnitTests.java
@@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.*;
import org.bson.Document;
import org.junit.jupiter.api.Test;
-import org.springframework.data.mongodb.core.aggregation.Aggregation.SystemVariable;
import org.springframework.data.mongodb.core.aggregation.ObjectOperators.MergeObjects;
/**