ReplaceWith class

$replaceWith aggregation stage

Stage description

Available since MongoDB version 4.2

Replaces the input document with the specified document. The operation replaces all existing fields in the input document, including the _id field. With $replaceWith, you can promote an embedded document to the top-level. You can also specify a new document as the replacement.

The $replaceWith is an alias for $replaceRoot.

Examples:

Dart code:

ReplaceWith(Field('name')).build()

Equivalent mongoDB aggregation stage:

{ $replaceWith: { newRoot: "$name" } }

Dart code:

ReplaceWith(MergeObjects([
  {
    '_id': Field('_id'),
    'first': '',
    'last': ''
  },
  Field('name')
])).build()

Equivalent mongoDB aggregation stage:

{ $replaceWith: {
  newRoot: {
    $mergeObjects: [ { _id: "$_id", first: "", last: "" }, "$name" ]
  }
}}

https://docs.mongodb.com/manual/reference/operator/aggregation/replaceWith/

Inheritance

Constructors

ReplaceWith(dynamic replacement)
Creates $replaceWith aggregation stage

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build() Map<String, Object>
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited