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