Answer the question
In order to leave comments, you need to log in
How to group records in MongoDB?
Good afternoon. I have many entries in my collection. Some entries are the same, only the size field is different.
Example entries
{
"_id": {
"$oid": "5fc3695ae110660e88c402921"
},
"ip": "112.0.1.1",
"port1": "2222",
"ip": "172.22.122.0",
"port2": "172.22.122.0",
"protocol": "TCP",
"size": "241",
"__v": 0
}
{
"_id": {
"$oid": "5fc3695ae110660e88c402921"
},
"ip": "112.0.1.1",
"port1": "2222",
"ip": "172.22.122.0",
"port2": "172.22.122.0",
"protocol": "TCP",
"size": "55",
"__v": 0
}
{
"_id": {
"$oid": "5fc3695ae110660e88c402921"
},
"ip": "112.0.1.1",
"port1": "2222",
"ip": "172.22.122.0",
"port2": "172.22.122.0",
"protocol": "TCP",
"size": "ВОТ ТУТ СУММА",
"count": "ВОТ ТУТ количество одинаковых записей",
"__v": 0
}
Answer the question
In order to leave comments, you need to log in
The best option would be to use aggregations .
See how the commands work: $group , $sum , $project , $lookup and $cond .
I think this gentleman's set is more than enough to solve the
Luck problem)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question