java.lang.Object
org.springframework.data.mongodb.core.aggregation.OutOperation
All Implemented Interfaces:
AggregationOperation

public class OutOperation extends Object implements AggregationOperation
Encapsulates the $out-operation.

We recommend to use the static factory method Aggregation.out(String) instead of creating instances of this class directly.

Author:
Nikolay Bogdanov, Christoph Strobl
See Also:
  • Constructor Details

    • OutOperation

      public OutOperation(String outCollectionName)
      Parameters:
      outCollectionName - Collection name to export the results. Must not be null.
  • Method Details

    • in

      public OutOperation in(@Nullable String database)
      Optionally specify the database of the target collection.
      NOTE: Requires MongoDB 4.2 or later.
      Parameters:
      database - can be null. Defaulted to aggregation target database.
      Returns:
      new instance of OutOperation.
      Since:
      2.2
    • uniqueKey

      public OutOperation uniqueKey(@Nullable String key)
      Optionally specify the field that uniquely identifies a document in the target collection.
      For convenience the given key can either be a single field name or the Json representation of a key Document.
      
       // {
       //    "field-1" : 1
       // }
       .uniqueKey("field-1")
      
       // {
       //    "field-1" : 1,
       //    "field-2" : 1
       // }
       .uniqueKey("{ 'field-1' : 1, 'field-2' : 1}")
       
      NOTE: Requires MongoDB 4.2 or later.
      Parameters:
      key - can be null. Server uses _id when null.
      Returns:
      new instance of OutOperation.
      Since:
      2.2
    • uniqueKeyOf

      public OutOperation uniqueKeyOf(Iterable<String> fields)
      Optionally specify the fields that uniquely identifies a document in the target collection.
      
       // {
       //    "field-1" : 1
       //    "field-2" : 1
       // }
       .uniqueKeyOf(Arrays.asList("field-1", "field-2"))
       
      NOTE: Requires MongoDB 4.2 or later.
      Parameters:
      fields - must not be null.
      Returns:
      new instance of OutOperation.
      Since:
      2.2
    • mode

      public OutOperation mode(OutOperation.OutMode mode)
      Specify how to merge the aggregation output with the target collection.
      NOTE: Requires MongoDB 4.2 or later.
      Parameters:
      mode - must not be null.
      Returns:
      new instance of OutOperation.
      Since:
      2.2
    • replaceCollection

      public OutOperation replaceCollection()
      Replace the target collection.
      NOTE: Requires MongoDB 4.2 or later.
      Returns:
      new instance of OutOperation.
      Since:
      2.2
      See Also:
    • replaceDocuments

      public OutOperation replaceDocuments()
      Replace/Upsert documents in the target collection.
      NOTE: Requires MongoDB 4.2 or later.
      Returns:
      new instance of OutOperation.
      Since:
      2.2
      See Also:
    • insertDocuments

      public OutOperation insertDocuments()
      Insert documents to the target collection.
      NOTE: Requires MongoDB 4.2 or later.
      Returns:
      new instance of OutOperation.
      Since:
      2.2
      See Also:
    • toDocument

      public org.bson.Document toDocument(AggregationOperationContext context)
      Description copied from interface: AggregationOperation
      Turns the AggregationOperation into a Document by using the given AggregationOperationContext.
      Specified by:
      toDocument in interface AggregationOperation
      Parameters:
      context - the AggregationOperationContext to operate within. Must not be null.
      Returns:
      the Document
    • getOperator

      public String getOperator()
      Description copied from interface: AggregationOperation
      Return the MongoDB operator that is used for this AggregationOperation. Aggregation operations should implement this method to avoid document rendering.
      Specified by:
      getOperator in interface AggregationOperation
      Returns:
      the operator used for this AggregationOperation.