@@ -96,11 +96,12 @@ public OutOperation in(@Nullable String database) {
9696 * .uniqueKey("{ 'field-1' : 1, 'field-2' : 1}")
9797 * </pre>
9898 *
99- * <strong>NOTE:</strong> Requires MongoDB 4.2 or later .
99+ * <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0 .
100100 *
101101 * @param key can be {@literal null}. Server uses {@literal _id} when {@literal null}.
102102 * @return new instance of {@link OutOperation}.
103103 * @since 2.2
104+ * @deprecated no longer applicable for MongoDB 5+
104105 */
105106 public OutOperation uniqueKey (@ Nullable String key ) {
106107
@@ -120,11 +121,12 @@ public OutOperation uniqueKey(@Nullable String key) {
120121 * .uniqueKeyOf(Arrays.asList("field-1", "field-2"))
121122 * </pre>
122123 *
123- * <strong>NOTE:</strong> Requires MongoDB 4.2 or later .
124+ * <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0 .
124125 *
125126 * @param fields must not be {@literal null}.
126127 * @return new instance of {@link OutOperation}.
127128 * @since 2.2
129+ * @deprecated no longer applicable for MongoDB 5+
128130 */
129131 public OutOperation uniqueKeyOf (Iterable <String > fields ) {
130132
@@ -138,11 +140,12 @@ public OutOperation uniqueKeyOf(Iterable<String> fields) {
138140
139141 /**
140142 * 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 .
142144 *
143145 * @param mode must not be {@literal null}.
144146 * @return new instance of {@link OutOperation}.
145147 * @since 2.2
148+ * @deprecated no longer applicable for MongoDB 5+
146149 */
147150 public OutOperation mode (OutMode mode ) {
148151
@@ -152,35 +155,38 @@ public OutOperation mode(OutMode mode) {
152155
153156 /**
154157 * 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 .
156159 *
157160 * @return new instance of {@link OutOperation}.
158161 * @see OutMode#REPLACE_COLLECTION
159162 * @since 2.2
163+ * @deprecated no longer applicable for MongoDB 5+
160164 */
161165 public OutOperation replaceCollection () {
162166 return mode (OutMode .REPLACE_COLLECTION );
163167 }
164168
165169 /**
166170 * 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 .
168172 *
169173 * @return new instance of {@link OutOperation}.
170174 * @see OutMode#REPLACE
171175 * @since 2.2
176+ * @deprecated no longer applicable for MongoDB 5+
172177 */
173178 public OutOperation replaceDocuments () {
174179 return mode (OutMode .REPLACE );
175180 }
176181
177182 /**
178183 * 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 .
180185 *
181186 * @return new instance of {@link OutOperation}.
182187 * @see OutMode#INSERT
183188 * @since 2.2
189+ * @deprecated no longer applicable for MongoDB 5+
184190 */
185191 public OutOperation insertDocuments () {
186192 return mode (OutMode .INSERT );
@@ -190,7 +196,10 @@ public OutOperation insertDocuments() {
190196 public Document toDocument (AggregationOperationContext context ) {
191197
192198 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 ));
194203 }
195204
196205 Assert .state (mode != null , "Mode must not be null" );
@@ -215,15 +224,17 @@ public String getOperator() {
215224 }
216225
217226 private boolean requiresMongoDb42Format () {
218- return StringUtils . hasText ( databaseName ) || mode != null || uniqueKey != null ;
227+ return mode != null || uniqueKey != null ;
219228 }
220229
221230 /**
222231 * The mode for merging the aggregation pipeline output.
223232 *
224233 * @author Christoph Strobl
225234 * @since 2.2
235+ * @deprecated no longer applicable for MongoDB 5+
226236 */
237+ @ Deprecated
227238 public enum OutMode {
228239
229240 /**
0 commit comments