@@ -96,12 +96,14 @@ 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 */
106+ @ Deprecated
105107 public OutOperation uniqueKey (@ Nullable String key ) {
106108
107109 Document uniqueKey = key == null ? null : BsonUtils .toDocumentOrElse (key , it -> new Document (it , 1 ));
@@ -120,12 +122,14 @@ public OutOperation uniqueKey(@Nullable String key) {
120122 * .uniqueKeyOf(Arrays.asList("field-1", "field-2"))
121123 * </pre>
122124 *
123- * <strong>NOTE:</strong> Requires MongoDB 4.2 or later .
125+ * <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0 .
124126 *
125127 * @param fields must not be {@literal null}.
126128 * @return new instance of {@link OutOperation}.
127129 * @since 2.2
130+ * @deprecated no longer applicable for MongoDB 5+
128131 */
132+ @ Deprecated
129133 public OutOperation uniqueKeyOf (Iterable <String > fields ) {
130134
131135 Assert .notNull (fields , "Fields must not be null" );
@@ -138,12 +142,14 @@ public OutOperation uniqueKeyOf(Iterable<String> fields) {
138142
139143 /**
140144 * 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 .
142146 *
143147 * @param mode must not be {@literal null}.
144148 * @return new instance of {@link OutOperation}.
145149 * @since 2.2
150+ * @deprecated no longer applicable for MongoDB 5+
146151 */
152+ @ Deprecated
147153 public OutOperation mode (OutMode mode ) {
148154
149155 Assert .notNull (mode , "Mode must not be null" );
@@ -152,36 +158,42 @@ public OutOperation mode(OutMode mode) {
152158
153159 /**
154160 * 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 .
156162 *
157163 * @return new instance of {@link OutOperation}.
158164 * @see OutMode#REPLACE_COLLECTION
159165 * @since 2.2
166+ * @deprecated no longer applicable for MongoDB 5+
160167 */
168+ @ Deprecated
161169 public OutOperation replaceCollection () {
162170 return mode (OutMode .REPLACE_COLLECTION );
163171 }
164172
165173 /**
166174 * 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 .
168176 *
169177 * @return new instance of {@link OutOperation}.
170178 * @see OutMode#REPLACE
171179 * @since 2.2
180+ * @deprecated no longer applicable for MongoDB 5+
172181 */
182+ @ Deprecated
173183 public OutOperation replaceDocuments () {
174184 return mode (OutMode .REPLACE );
175185 }
176186
177187 /**
178188 * 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 .
180190 *
181191 * @return new instance of {@link OutOperation}.
182192 * @see OutMode#INSERT
183193 * @since 2.2
194+ * @deprecated no longer applicable for MongoDB 5+
184195 */
196+ @ Deprecated
185197 public OutOperation insertDocuments () {
186198 return mode (OutMode .INSERT );
187199 }
@@ -190,7 +202,10 @@ public OutOperation insertDocuments() {
190202 public Document toDocument (AggregationOperationContext context ) {
191203
192204 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 ));
194209 }
195210
196211 Assert .state (mode != null , "Mode must not be null" );
@@ -215,15 +230,17 @@ public String getOperator() {
215230 }
216231
217232 private boolean requiresMongoDb42Format () {
218- return StringUtils . hasText ( databaseName ) || mode != null || uniqueKey != null ;
233+ return mode != null || uniqueKey != null ;
219234 }
220235
221236 /**
222237 * The mode for merging the aggregation pipeline output.
223238 *
224239 * @author Christoph Strobl
225240 * @since 2.2
241+ * @deprecated no longer applicable for MongoDB 5+
226242 */
243+ @ Deprecated
227244 public enum OutMode {
228245
229246 /**
0 commit comments