Pipeline mongodb là gì
Docs Home → MongoDB Manual On this page
The $inc operator increments a field by a specified value and has the following form:
To specify a Starting in MongoDB 5.0, update operators process document fields with string-based names in lexicographic order. Fields with numeric names are processed in numeric order. See Update Operators Behavior for details. The $inc operator accepts positive and negative values. If the field does not exist, $inc creates the field and sets the field to the specified value. Use of the $inc operator on a field with a null value will generate an error. $inc is an atomic operation within a single document. Starting in MongoDB 5.0, mongod no longer raises an error when you use an update operator like $inc with an empty operand expression ( { } ). An empty update results in no changes and no oplog entry is created (meaning that the operation is a no-op). Create the products collection:
The following updateOne() operation uses the $inc operator to:
The updated document would resemble:
Tip See also:
Docs Home → MongoDB Manual Aggregation operations process multiple documents and return computed results. You can use aggregation operations to:
To perform aggregation operations, you can use: An aggregation pipeline consists of one or more stages that process documents:
Starting in MongoDB 4.2, you can also update documents with an aggregation pipeline. See Updates with Aggregation Pipeline. The following aggregation pipeline example contains two stages and returns the total order quantity of medium size pizzas grouped by pizza name:
The $match stage:
The $group stage:
For runnable examples containing sample input documents, see Complete Aggregation Pipeline Examples. You can use the following single purpose aggregation methods to aggregate documents from a single collection: The single purpose aggregation methods are simple but lack the capabilities of an aggregation pipeline. Starting in MongoDB 5.0, map-reduce is deprecated:
For examples of aggregation pipeline alternatives to map-reduce, see:
For a feature comparison of aggregation pipelines and map-reduce, see Aggregation Commands Comparison. To learn more about aggregations, see: ← Tailable CursorsAggregation Pipeline → |