$set class
$set aggregation stage
Stage description
Available since MongoDB version 4.2
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.
You can include one or more $set stages in an aggregation operation.
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 $set, use with
$concatArrays (ConcatArrays).
Dart code:
$set([
fieldSum('totalHomework', Field('homework')),
fieldSum('totalQuiz', r'$quiz')
]).build()
or
$set.raw({
...FieldExpression('totalHomework', $sum(Field('homework'))).build(),
'totalQuiz': $sum(r'$quiz')
}).build()
Equivalent mongoDB aggregation stage:
{
$set: {
totalHomework: { $sum: "$homework" },
totalQuiz: { $sum: "$quiz" }
}
}
https://docs.mongodb.com/manual/reference/operator/aggregation/set/
- Inheritance
Constructors
-
$set(List<
FieldExpression< expressions)ExpressionContent> > -
Creates
$setaggregation stage - $set.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