|
|
|
@ -96,12 +96,14 @@ public class OutOperation implements AggregationOperation { |
|
|
|
* .uniqueKey("{ 'field-1' : 1, 'field-2' : 1}") |
|
|
|
* .uniqueKey("{ 'field-1' : 1, 'field-2' : 1}") |
|
|
|
* </pre> |
|
|
|
* </pre> |
|
|
|
* |
|
|
|
* |
|
|
|
* <strong>NOTE:</strong> Requires MongoDB 4.2 or later. |
|
|
|
* <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param key can be {@literal null}. Server uses {@literal _id} when {@literal null}. |
|
|
|
* @param key can be {@literal null}. Server uses {@literal _id} when {@literal null}. |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @since 2.2 |
|
|
|
* @since 2.2 |
|
|
|
|
|
|
|
* @deprecated no longer applicable for MongoDB 5+ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public OutOperation uniqueKey(@Nullable String key) { |
|
|
|
public OutOperation uniqueKey(@Nullable String key) { |
|
|
|
|
|
|
|
|
|
|
|
Document uniqueKey = key == null ? null : BsonUtils.toDocumentOrElse(key, it -> new Document(it, 1)); |
|
|
|
Document uniqueKey = key == null ? null : BsonUtils.toDocumentOrElse(key, it -> new Document(it, 1)); |
|
|
|
@ -120,12 +122,14 @@ public class OutOperation implements AggregationOperation { |
|
|
|
* .uniqueKeyOf(Arrays.asList("field-1", "field-2")) |
|
|
|
* .uniqueKeyOf(Arrays.asList("field-1", "field-2")) |
|
|
|
* </pre> |
|
|
|
* </pre> |
|
|
|
* |
|
|
|
* |
|
|
|
* <strong>NOTE:</strong> Requires MongoDB 4.2 or later. |
|
|
|
* <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param fields must not be {@literal null}. |
|
|
|
* @param fields must not be {@literal null}. |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @since 2.2 |
|
|
|
* @since 2.2 |
|
|
|
|
|
|
|
* @deprecated no longer applicable for MongoDB 5+ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public OutOperation uniqueKeyOf(Iterable<String> fields) { |
|
|
|
public OutOperation uniqueKeyOf(Iterable<String> fields) { |
|
|
|
|
|
|
|
|
|
|
|
Assert.notNull(fields, "Fields must not be null"); |
|
|
|
Assert.notNull(fields, "Fields must not be null"); |
|
|
|
@ -138,12 +142,14 @@ public class OutOperation implements AggregationOperation { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Specify how to merge the aggregation output with the target collection. <br /> |
|
|
|
* Specify how to merge the aggregation output with the target collection. <br /> |
|
|
|
* <strong>NOTE:</strong> Requires MongoDB 4.2 or later. |
|
|
|
* <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param mode must not be {@literal null}. |
|
|
|
* @param mode must not be {@literal null}. |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @since 2.2 |
|
|
|
* @since 2.2 |
|
|
|
|
|
|
|
* @deprecated no longer applicable for MongoDB 5+ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public OutOperation mode(OutMode mode) { |
|
|
|
public OutOperation mode(OutMode mode) { |
|
|
|
|
|
|
|
|
|
|
|
Assert.notNull(mode, "Mode must not be null"); |
|
|
|
Assert.notNull(mode, "Mode must not be null"); |
|
|
|
@ -152,36 +158,42 @@ public class OutOperation implements AggregationOperation { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Replace the target collection. <br /> |
|
|
|
* Replace the target collection. <br /> |
|
|
|
* <strong>NOTE:</strong> Requires MongoDB 4.2 or later. |
|
|
|
* <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0. |
|
|
|
* |
|
|
|
* |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @see OutMode#REPLACE_COLLECTION |
|
|
|
* @see OutMode#REPLACE_COLLECTION |
|
|
|
* @since 2.2 |
|
|
|
* @since 2.2 |
|
|
|
|
|
|
|
* @deprecated no longer applicable for MongoDB 5+ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public OutOperation replaceCollection() { |
|
|
|
public OutOperation replaceCollection() { |
|
|
|
return mode(OutMode.REPLACE_COLLECTION); |
|
|
|
return mode(OutMode.REPLACE_COLLECTION); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Replace/Upsert documents in the target collection. <br /> |
|
|
|
* Replace/Upsert documents in the target collection. <br /> |
|
|
|
* <strong>NOTE:</strong> Requires MongoDB 4.2 or later. |
|
|
|
* <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0. |
|
|
|
* |
|
|
|
* |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @see OutMode#REPLACE |
|
|
|
* @see OutMode#REPLACE |
|
|
|
* @since 2.2 |
|
|
|
* @since 2.2 |
|
|
|
|
|
|
|
* @deprecated no longer applicable for MongoDB 5+ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public OutOperation replaceDocuments() { |
|
|
|
public OutOperation replaceDocuments() { |
|
|
|
return mode(OutMode.REPLACE); |
|
|
|
return mode(OutMode.REPLACE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Insert documents to the target collection. <br /> |
|
|
|
* Insert documents to the target collection. <br /> |
|
|
|
* <strong>NOTE:</strong> Requires MongoDB 4.2 or later. |
|
|
|
* <strong>NOTE:</strong> Only suitable for 4.2+ to (not including) 5.0. |
|
|
|
* |
|
|
|
* |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @return new instance of {@link OutOperation}. |
|
|
|
* @see OutMode#INSERT |
|
|
|
* @see OutMode#INSERT |
|
|
|
* @since 2.2 |
|
|
|
* @since 2.2 |
|
|
|
|
|
|
|
* @deprecated no longer applicable for MongoDB 5+ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public OutOperation insertDocuments() { |
|
|
|
public OutOperation insertDocuments() { |
|
|
|
return mode(OutMode.INSERT); |
|
|
|
return mode(OutMode.INSERT); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -190,7 +202,10 @@ public class OutOperation implements AggregationOperation { |
|
|
|
public Document toDocument(AggregationOperationContext context) { |
|
|
|
public Document toDocument(AggregationOperationContext context) { |
|
|
|
|
|
|
|
|
|
|
|
if (!requiresMongoDb42Format()) { |
|
|
|
if (!requiresMongoDb42Format()) { |
|
|
|
return new Document("$out", collectionName); |
|
|
|
if (!StringUtils.hasText(databaseName)) { |
|
|
|
|
|
|
|
return new Document(getOperator(), collectionName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return new Document(getOperator(), new Document("db", databaseName).append("coll", collectionName)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Assert.state(mode != null, "Mode must not be null"); |
|
|
|
Assert.state(mode != null, "Mode must not be null"); |
|
|
|
@ -215,7 +230,7 @@ public class OutOperation implements AggregationOperation { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean requiresMongoDb42Format() { |
|
|
|
private boolean requiresMongoDb42Format() { |
|
|
|
return StringUtils.hasText(databaseName) || mode != null || uniqueKey != null; |
|
|
|
return mode != null || uniqueKey != null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -223,7 +238,9 @@ public class OutOperation implements AggregationOperation { |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Christoph Strobl |
|
|
|
* @author Christoph Strobl |
|
|
|
* @since 2.2 |
|
|
|
* @since 2.2 |
|
|
|
|
|
|
|
* @deprecated no longer applicable for MongoDB 5+ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public enum OutMode { |
|
|
|
public enum OutMode { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|