Answer the question
In order to leave comments, you need to log in
How to fix error when querying mongodb?
Good afternoon. I have a collection
doing sorting. I count the number of duplicates and the sum of the package sizes (Size). Then I write to another collection. Here's what I get
How do I put the sum of the packets, now this is the (count) field in the Size field? and remove the count field so that it is like this
Here is my code. I don't understand what needs to be changed?
var ss = mongoQLog.aggregate([ {
$group: { _id: { name: "$ip", value: "$port2", value2:"$protocol"},
doc: { $last: "$$ROOT" }, // Retrieve only last doc in a group
count:{$sum:"$size"},
total:{$sum:1}
}
},
{
$replaceRoot: { newRoot: { $mergeObjects: [{ count: '$count',total:"$total" }, '$doc'] }} // replace doc as object as new root of document
},
{ $out : 'collection_new' }]).exec(function ( e, d ) {
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question