$addFields class
$addFields
aggregation stage
Stage description.
Adds new fields to documents. $addFields outputs documents that contain
all existing fields from the input documents and newly added fields.
The $addFields stage is equivalent to a $project stage that explicitly
specifies all existing fields in the input documents and adds the
new fields. You can include one or more $addFields
stages in an
aggregation pipeline.
To add field or fields to embedded documents (including documents in arrays) use the dot notation.
To add an element to an existing array field with $addFields
, use with
$concatArrays
(ConcatArrays
).
Example:
Dart code
$addFields([
fieldSum('totalHomework', Field('homework')),
fieldSum('totalQuiz', r'$quiz')
]).build()
or
$addFields.raw({
'totalHomework': $sum(Field('homework')),
'totalQuiz': $sum(r'$quiz')
}).build()
Equivalent mongoDB aggregation stage:
{
$addFields: {
totalHomework: { $sum: "$homework" } ,
totalQuiz: { $sum: "$quiz" }
}
}
https://docs.mongodb.com/manual/reference/operator/aggregation/addFields/
- Inheritance
Constructors
-
$addFields.new(List<
FieldExpression< expressions)ExpressionContent> > -
Creates
$addFields
aggregation stage - $addFields.raw(MongoDocument raw)
Properties
- content → ExpressionContent
-
no setterinherited
-
entry
↔ MapEntry<
String, ExpressionContent> -
getter/setter pairinherited
- fieldName → String
-
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → String
-
no setterinherited
- rawContent → dynamic
-
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stageName → String
-
no setterinherited
Methods
-
build(
) → MongoDocument -
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