The concepts of aggregation (among other modeling concepts) have in the link @Maniero already commented: What is the difference between Association, Aggregation and Composition in OOP?
The aggregation operations in the mongodb
are operations that group the data and return computed results, such as sums and counting for example.
Aggregation Operations process data Records and Return computed Results. Aggregation Operations group values from Multiple Documents Together, and can perform a Variety of Operations on the grouped data to Return a single result.
Of the documentation here: https://docs.mongodb.com/manual/aggregation/
In free translation:
Aggregation operations process data records and return
computed results. Aggregation operations group values of
various documents and can perform a variety of operations in the
grouped data to return a single result.
It is similar to the concept of GROUP BY
of a relational database.
In example of aggregation, counting elements would be for example, from such a data source:
[
{
"nome": "João",
"estado": "RJ",
"pais": "Brasil"
},
{
"nome": "Maria",
"estado": "RJ",
"pais": "Brasil"
},
{
"nome": "João",
"estado": "SP",
"pais": "Brasil"
},
{
"nome": "Maria",
"estado": "SP",
"pais": "Brasil"
},
{
"nome": "João",
"estado": "PB",
"pais": "Brasil"
},
{
"nome": "Maria",
"estado": "PB",
"pais": "Brasil"
},
{
"nome": "John",
"estado": "CA",
"pais": "USA"
}
]
If you want to aggregate state values and count the number of occurrences in each state, you could write an operation like this:
db.collection.aggregate([
{
"$group": {
_id: "$estado",
count: {
$sum: 1
}
}
}
])
That is, a "group" operation, by the "state" property, running "Count", adding 1 for each occurrence. The result of this aggregation operation will be:
[
{
"_id": "RJ",
"count": 2
},
{
"_id": "SP",
"count": 2
},
{
"_id": "PB",
"count": 2
},
{
"_id": "CA",
"count": 1
}
]
Can be seen running here: https://mongoplayground.net/p/TFE7xvjRGbz
All aggregation operations and commands can be found in the documentation: https://docs.mongodb.com/manual/reference/operator/aggregation/interface/
Related: https://answall.com/q/86715/101
– Maniero
This link has nothing to do with the question. The link is about OOP modeling concepts, the aggregation of the question is related to aggregating information and not model, as a
group by
query SQL, or make amap/reduce
of data– Ricardo Pontual
If it has nothing to do I would advise people not to use what has a name of something that is not what it says:
estou precisando de ajuda para entender o conceito teórico de Aggregate
and that has nothing to do with OOP according to the linked answer, is a universal concept of computing.– Maniero
as to the name seems right, is the name of the functionality in the
mongodb
: https://docs.mongodb.com/manual/aggregation/ as well as onsql-sever
: https://docs.microsoft.com/en-us/sql/t-sql/functions/aggregate-functions-transact-sql only the concepts are different, here at the level of information, in OOP, at the level of modeling– Ricardo Pontual
"only the concepts are different, here at the level of information, in OOP, at the level of modeling" This is no different concept, it is application of the same concept in different contexts.
– Bacco
Sorry @Bacco, even though I won’t be able to convince you, I will defend my point. OOP aggregation is a modeling concept where one object is part of the other. The aggregation in the data, which is what you have in the question, are operations of calculation, grouping and data transformation, which does not require that there are two objects involved, and more, if there are, the objects do not need to be part of each other, that is the difference. A "distinct" is an aggregation operation, which has nothing to do with OOP aggregation, is done in a single column, does not involve 2 objects, understand? So they’re different concepts
– Ricardo Pontual