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