A
A
Astral1004982020-12-14 21:29:25
Node.js
Astral100498, 2020-12-14 21:29:25

How to fix error when querying mongodb?

Good afternoon. I have a collection 5fd7ad351fe74905139623.png

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 5fd7ae18001b8238299369.png

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 5fd7aed2cb7a8447423979.png

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 question

Ask a Question

731 491 924 answers to any question