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. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

build() Map<String, dynamic>
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

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