@@ -102,12 +102,12 @@ public class Aggregation {
102
102
private final AggregationOptions options ;
103
103
104
104
/**
105
- * Creates a new {@link Aggregation} from the given {@link AggregationOperation }s.
105
+ * Creates a new {@link Aggregation} from the given {@link AggregationStage }s.
106
106
*
107
107
* @param operations must not be {@literal null} or empty.
108
108
*/
109
- public static Aggregation newAggregation (List <? extends AggregationOperation > operations ) {
110
- return newAggregation (operations .toArray (new AggregationOperation [ operations . size ()] ));
109
+ public static Aggregation newAggregation (List <? extends AggregationStage > operations ) {
110
+ return newAggregation (operations .toArray (AggregationStage []:: new ));
111
111
}
112
112
113
113
/**
@@ -119,6 +119,16 @@ public static Aggregation newAggregation(AggregationOperation... operations) {
119
119
return new Aggregation (operations );
120
120
}
121
121
122
+ /**
123
+ * Creates a new {@link Aggregation} from the given {@link AggregationOperation}s.
124
+ *
125
+ * @param stages must not be {@literal null} or empty.
126
+ * @since 4.1
127
+ */
128
+ public static Aggregation newAggregation (AggregationStage ... stages ) {
129
+ return new Aggregation (stages );
130
+ }
131
+
122
132
/**
123
133
* Creates a new {@link AggregationUpdate} from the given {@link AggregationOperation}s.
124
134
*
@@ -130,6 +140,17 @@ public static AggregationUpdate newUpdate(AggregationOperation... operations) {
130
140
return AggregationUpdate .from (Arrays .asList (operations ));
131
141
}
132
142
143
+ /**
144
+ * Creates a new {@link AggregationUpdate} from the given {@link AggregationOperation}s.
145
+ *
146
+ * @param operations can be {@literal empty} but must not be {@literal null}.
147
+ * @return new instance of {@link AggregationUpdate}.
148
+ * @since 4.1
149
+ */
150
+ public static AggregationUpdate newUpdate (AggregationStage ... operations ) {
151
+ return AggregationUpdate .updateFrom (Arrays .asList (operations ));
152
+ }
153
+
133
154
/**
134
155
* Returns a copy of this {@link Aggregation} with the given {@link AggregationOptions} set. Note that options are
135
156
* supported in MongoDB version 2.6+.
@@ -141,7 +162,7 @@ public static AggregationUpdate newUpdate(AggregationOperation... operations) {
141
162
public Aggregation withOptions (AggregationOptions options ) {
142
163
143
164
Assert .notNull (options , "AggregationOptions must not be null" );
144
- return new Aggregation (this .pipeline .getOperations (), options );
165
+ return new Aggregation (this .pipeline .getStages (), options );
145
166
}
146
167
147
168
/**
@@ -150,8 +171,8 @@ public Aggregation withOptions(AggregationOptions options) {
150
171
* @param type must not be {@literal null}.
151
172
* @param operations must not be {@literal null} or empty.
152
173
*/
153
- public static <T > TypedAggregation <T > newAggregation (Class <T > type , List <? extends AggregationOperation > operations ) {
154
- return newAggregation (type , operations .toArray (new AggregationOperation [ operations . size ()] ));
174
+ public static <T > TypedAggregation <T > newAggregation (Class <T > type , List <? extends AggregationStage > operations ) {
175
+ return newAggregation (type , operations .toArray (AggregationStage []:: new ));
155
176
}
156
177
157
178
/**
@@ -164,6 +185,17 @@ public static <T> TypedAggregation<T> newAggregation(Class<T> type, AggregationO
164
185
return new TypedAggregation <T >(type , operations );
165
186
}
166
187
188
+ /**
189
+ * Creates a new {@link TypedAggregation} for the given type and {@link AggregationOperation}s.
190
+ *
191
+ * @param type must not be {@literal null}.
192
+ * @param stages must not be {@literal null} or empty.
193
+ * @since 4.1
194
+ */
195
+ public static <T > TypedAggregation <T > newAggregation (Class <T > type , AggregationStage ... stages ) {
196
+ return new TypedAggregation <>(type , stages );
197
+ }
198
+
167
199
/**
168
200
* Creates a new {@link Aggregation} from the given {@link AggregationOperation}s.
169
201
*
@@ -173,6 +205,15 @@ protected Aggregation(AggregationOperation... aggregationOperations) {
173
205
this (asAggregationList (aggregationOperations ));
174
206
}
175
207
208
+ /**
209
+ * Creates a new {@link Aggregation} from the given {@link AggregationOperation}s.
210
+ *
211
+ * @param aggregationOperations must not be {@literal null} or empty.
212
+ */
213
+ protected Aggregation (AggregationStage ... aggregationOperations ) {
214
+ this (Arrays .asList (aggregationOperations ));
215
+ }
216
+
176
217
/**
177
218
* @param aggregationOperations must not be {@literal null} or empty.
178
219
* @return
@@ -189,7 +230,7 @@ protected static List<AggregationOperation> asAggregationList(AggregationOperati
189
230
*
190
231
* @param aggregationOperations must not be {@literal null} or empty.
191
232
*/
192
- protected Aggregation (List <AggregationOperation > aggregationOperations ) {
233
+ protected Aggregation (List <? extends AggregationStage > aggregationOperations ) {
193
234
this (aggregationOperations , DEFAULT_OPTIONS );
194
235
}
195
236
@@ -199,7 +240,7 @@ protected Aggregation(List<AggregationOperation> aggregationOperations) {
199
240
* @param aggregationOperations must not be {@literal null}.
200
241
* @param options must not be {@literal null} or empty.
201
242
*/
202
- protected Aggregation (List <AggregationOperation > aggregationOperations , AggregationOptions options ) {
243
+ protected Aggregation (List <? extends AggregationStage > aggregationOperations , AggregationOptions options ) {
203
244
204
245
Assert .notNull (aggregationOperations , "AggregationOperations must not be null" );
205
246
Assert .notNull (options , "AggregationOptions must not be null" );
@@ -638,6 +679,17 @@ public static FacetOperationBuilder facet(AggregationOperation... aggregationOpe
638
679
return facet ().and (aggregationOperations );
639
680
}
640
681
682
+ /**
683
+ * Creates a new {@link FacetOperationBuilder} given {@link Aggregation}.
684
+ *
685
+ * @param stages the sub-pipeline, must not be {@literal null}.
686
+ * @return new instance of {@link FacetOperation}.
687
+ * @since 4.1
688
+ */
689
+ public static FacetOperationBuilder facet (AggregationStage ... stages ) {
690
+ return facet ().and (stages );
691
+ }
692
+
641
693
/**
642
694
* Creates a new {@link LookupOperation}.
643
695
*
@@ -668,14 +720,14 @@ public static LookupOperation lookup(Field from, Field localField, Field foreign
668
720
669
721
/**
670
722
* Entrypoint for creating {@link LookupOperation $lookup} using a fluent builder API.
723
+ *
671
724
* <pre class="code">
672
- * Aggregation.lookup().from("restaurants")
673
- * .localField("restaurant_name")
674
- * .foreignField("name")
675
- * .let(newVariable("orders_drink").forField("drink"))
676
- * .pipeline(match(ctx -> new Document("$expr", new Document("$in", List.of("$$orders_drink", "$beverages")))))
677
- * .as("matches")
725
+ * Aggregation.lookup().from("restaurants").localField("restaurant_name").foreignField("name")
726
+ * .let(newVariable("orders_drink").forField("drink"))
727
+ * .pipeline(match(ctx -> new Document("$expr", new Document("$in", List.of("$$orders_drink", "$beverages")))))
728
+ * .as("matches")
678
729
* </pre>
730
+ *
679
731
* @return new instance of {@link LookupOperationBuilder}.
680
732
* @since 4.1
681
733
*/
0 commit comments