@@ -98,13 +98,15 @@ public OutOperation in(@Nullable String database) {
98
98
* .uniqueKey("{ 'field-1' : 1, 'field-2' : 1}")
99
99
* </pre>
100
100
*
101
- * <strong>NOTE:</strong> Requires MongoDB 4.2 or later .
101
+ * <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0 .
102
102
*
103
103
* @param key can be {@literal null}. Server uses {@literal _id} when {@literal null}.
104
104
* @return new instance of {@link OutOperation}.
105
105
* @since 2.2
106
+ * @deprecated no longer applicable for MongoDB 5+
106
107
*/
107
108
@ Contract ("_ -> new" )
109
+ @ Deprecated
108
110
public OutOperation uniqueKey (@ Nullable String key ) {
109
111
110
112
Document uniqueKey = key == null ? null : BsonUtils .toDocumentOrElse (key , it -> new Document (it , 1 ));
@@ -123,13 +125,15 @@ public OutOperation uniqueKey(@Nullable String key) {
123
125
* .uniqueKeyOf(Arrays.asList("field-1", "field-2"))
124
126
* </pre>
125
127
*
126
- * <strong>NOTE:</strong> Requires MongoDB 4.2 or later .
128
+ * <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0 .
127
129
*
128
130
* @param fields must not be {@literal null}.
129
131
* @return new instance of {@link OutOperation}.
130
132
* @since 2.2
133
+ * @deprecated no longer applicable for MongoDB 5+
131
134
*/
132
135
@ Contract ("_ -> new" )
136
+ @ Deprecated
133
137
public OutOperation uniqueKeyOf (Iterable <String > fields ) {
134
138
135
139
Assert .notNull (fields , "Fields must not be null" );
@@ -142,13 +146,15 @@ public OutOperation uniqueKeyOf(Iterable<String> fields) {
142
146
143
147
/**
144
148
* Specify how to merge the aggregation output with the target collection. <br />
145
- * <strong>NOTE:</strong> Requires MongoDB 4.2 or later .
149
+ * <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0 .
146
150
*
147
151
* @param mode must not be {@literal null}.
148
152
* @return new instance of {@link OutOperation}.
149
153
* @since 2.2
154
+ * @deprecated no longer applicable for MongoDB 5+
150
155
*/
151
156
@ Contract ("_ -> new" )
157
+ @ Deprecated
152
158
public OutOperation mode (OutMode mode ) {
153
159
154
160
Assert .notNull (mode , "Mode must not be null" );
@@ -157,39 +163,45 @@ public OutOperation mode(OutMode mode) {
157
163
158
164
/**
159
165
* Replace the target collection. <br />
160
- * <strong>NOTE:</strong> Requires MongoDB 4.2 or later .
166
+ * <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0 .
161
167
*
162
168
* @return new instance of {@link OutOperation}.
163
169
* @see OutMode#REPLACE_COLLECTION
164
170
* @since 2.2
171
+ * @deprecated no longer applicable for MongoDB 5+
165
172
*/
166
173
@ Contract ("-> new" )
174
+ @ Deprecated
167
175
public OutOperation replaceCollection () {
168
176
return mode (OutMode .REPLACE_COLLECTION );
169
177
}
170
178
171
179
/**
172
180
* Replace/Upsert documents in the target collection. <br />
173
- * <strong>NOTE:</strong> Requires MongoDB 4.2 or later .
181
+ * <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0 .
174
182
*
175
183
* @return new instance of {@link OutOperation}.
176
184
* @see OutMode#REPLACE
177
185
* @since 2.2
186
+ * @deprecated no longer applicable for MongoDB 5+
178
187
*/
179
188
@ Contract ("-> new" )
189
+ @ Deprecated
180
190
public OutOperation replaceDocuments () {
181
191
return mode (OutMode .REPLACE );
182
192
}
183
193
184
194
/**
185
195
* Insert documents to the target collection. <br />
186
- * <strong>NOTE:</strong> Requires MongoDB 4.2 or later .
196
+ * <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0 .
187
197
*
188
198
* @return new instance of {@link OutOperation}.
189
199
* @see OutMode#INSERT
190
200
* @since 2.2
201
+ * @deprecated no longer applicable for MongoDB 5+
191
202
*/
192
203
@ Contract ("-> new" )
204
+ @ Deprecated
193
205
public OutOperation insertDocuments () {
194
206
return mode (OutMode .INSERT );
195
207
}
@@ -198,7 +210,10 @@ public OutOperation insertDocuments() {
198
210
public Document toDocument (AggregationOperationContext context ) {
199
211
200
212
if (!requiresMongoDb42Format ()) {
201
- return new Document ("$out" , collectionName );
213
+ if (!StringUtils .hasText (databaseName )) {
214
+ return new Document (getOperator (), collectionName );
215
+ }
216
+ return new Document (getOperator (), new Document ("db" , databaseName ).append ("coll" , collectionName ));
202
217
}
203
218
204
219
Assert .state (mode != null , "Mode must not be null" );
@@ -223,15 +238,17 @@ public String getOperator() {
223
238
}
224
239
225
240
private boolean requiresMongoDb42Format () {
226
- return StringUtils . hasText ( databaseName ) || mode != null || uniqueKey != null ;
241
+ return mode != null || uniqueKey != null ;
227
242
}
228
243
229
244
/**
230
245
* The mode for merging the aggregation pipeline output.
231
246
*
232
247
* @author Christoph Strobl
233
248
* @since 2.2
249
+ * @deprecated no longer applicable for MongoDB 5+
234
250
*/
251
+ @ Deprecated
235
252
public enum OutMode {
236
253
237
254
/**
0 commit comments