Class Set

java.lang.Object
dev.morphia.aggregation.stages.Stage
dev.morphia.aggregation.stages.Set

public class Set extends Stage
Adds new fields to documents. $set outputs documents that contain all existing fields from the input documents and newly added fields.

The $set stage is an alias for $addFields.

Both stages are equivalent to a $project stage that explicitly specifies all existing fields in the input documents and adds the new fields.

Since:
2.3
  • Method Details

    • set

      public static Set set()
      Creates a new Set stage
      Returns:
      the new stage
      MongoDB documentation
      Aggregration Pipeline Stage: $set
      Since server release
      4.2
    • field

      public Set field(String name, Object value)
      Add a field to the stage
      Parameters:
      name - the name of the new field
      value - the value expression
      Returns:
      this