Arrays MongoDB阵列副本

Arrays MongoDB阵列副本,arrays,mongodb,count,duplicates,Arrays,Mongodb,Count,Duplicates,我有下面的查询,它使用lookup创建一个新数组,以便“连接”两个集合,一旦合并了数据,y按“group”数据分组,并显示events字段,正如您可以看到的,它有重复项,例如“times this issues events”(此问题发生的次数),这就是它的意思。我想展示一些东西,比如: Group1 { Event 1 : 120 Times Event 2 : 2478 Times Event 3 : 120 Times } Group2 { Event 1 : 455 Times Eve

我有下面的查询,它使用lookup创建一个新数组,以便“连接”两个集合,一旦合并了数据,y按“group”数据分组,并显示events字段,正如您可以看到的,它有重复项,例如“times this issues events”(此问题发生的次数),这就是它的意思。我想展示一些东西,比如:

Group1
{
Event 1 : 120 Times
Event 2 : 2478 Times
Event 3 : 120 Times
}

Group2
{
Event 1 : 455 Times
Event 2 : 24  Times
Event 3 : 146 Times
}
我的代码

 db.events.aggregate([

   { $match : { netcode : "N000362" } },

    {
      $lookup:
        {
          from: "nodes",
          localField: "name",
          foreignField: "name",
          as: "event_joined"


        }

   },


  { $unwind:  {path: "$event_joined"}},


  { $project : { name : 1, event : 1, "event_joined.group": 1 ,_id:0} },

  { $unwind:  {path: "$event_joined"}},

  { $group : { _id : "$event_joined.group", eventos: { $push: "$event"} } },


])
输出:


我在MongoDB文档中进行了搜索和尝试,但我认为它缺少很多示例和语法

使用
{$addToSet:$event}
而不是
{$push:$event}
。看起来你的
$project+$unwind
阶段是多余的。再次感谢你,我会很快尝试,请不要离开:DinDect它是多余的,我只是在测试,有没有办法看看每一个我有多少?我不想删除重复的,但是,我想看看每一个我有多少抱歉误解了你的帖子。请尝试
{$group:{\u id:{group:$event\u joined.group],event:$event},count:{$sum:1}}
{
"_id" : "GFS-CALL-CENTER-EXTENDIDO",
"eventos" : [ 
    "Proactive Interface Output Utilisation", 
    "BGP Peer Down", 
    "Proactive Reachability", 
    "Proactive Interface Input Utilisation", 
    "Proactive Response Time", 
    "Proactive CPU", 
    "Proactive Memory Free", 
    "Proactive Interface Availability", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Reachability", 
    "Proactive Response Time", 
    "Proactive CPU", 
    "Proactive Memory Free", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Availability", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "BGP Peer Down", 
    "Proactive Reachability", 
    "Proactive CPU", 
    "Proactive Response Time", 
    "Proactive Memory Free", 
    "Proactive Interface Availability", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Availability", 
    "Proactive Reachability", 
    "Proactive Response Time", 
    "Proactive Interface Availability", 
    "Proactive Reachability", 
    "Proactive Response Time", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Reachability", 
    "Proactive Response Time", 
    "Proactive CPU", 
    "Proactive Memory Free", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Availability", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Reachability", 
    "Proactive Interface Output Utilisation", 
    "Proactive Response Time", 
    "Proactive CPU", 
    "Proactive Memory Free", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Availability", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "BGP Peer Down", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Reachability", 
    "Proactive CPU", 
    "Proactive Response Time", 
    "Proactive Memory Free", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Availability", 
    "Proactive Interface Output Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Reachability", 
    "Proactive Interface Output Utilisation", 
    "Proactive Response Time", 
    "Proactive CPU", 
    "Proactive Interface Output Utilisation", 
    "Proactive Memory Free", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Availability", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Reachability", 
    "Proactive Interface Output Utilisation", 
    "Proactive Response Time", 
    "Proactive CPU", 
    "BGP Peer Down", 
    "Proactive Memory Free", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Availability", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Reachability", 
    "Proactive CPU", 
    "Proactive Response Time", 
    "Proactive Memory Free", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Availability", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Reachability", 
    "BGP Peer Down", 
    "Proactive CPU", 
    "Proactive Response Time", 
    "Proactive Memory Free", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Availability", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "BGP Peer Down", 
    "SNMP DOWN", 
    "BGP Peer Down", 
    "Proactive Reachability", 
    "Proactive Interface Output Utilisation", 
    "Proactive CPU", 
    "Proactive Response Time", 
    "Proactive Interface Output Utilisation", 
    "Proactive Memory Free", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Availability", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "BGP Peer Down", 
    "Proactive Reachability", 
    "Proactive Interface Input Utilisation", 
    "Proactive CPU", 
    "Proactive Response Time", 
    "Proactive Interface Output Utilisation", 
    "Proactive Memory Free", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Availability", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Reachability", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive CPU", 
    "Proactive Response Time", 
    "Proactive Memory Free", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Availability", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Reachability", 
    "Proactive Interface Output Utilisation", 
    "Proactive CPU", 
    "Proactive Response Time", 
    "Proactive Memory Free", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Availability", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "BGP Peer Down", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
    "Proactive Interface Input Utilisation", 
    "Proactive Interface Output Utilisation", 
        "BGP Peer Down", 
        "Proactive Interface Output Utilisation", 
        "Proactive Reachability", 
        "Proactive CPU", 
        "Proactive Response Time", 
        "Proactive Interface Output Utilisation", 
        "Proactive Memory Free", 
        "Proactive Interface Input Utilisation", 
        "BGP Peer Down", 
        "Proactive Interface Availability", 
        "Proactive Interface Input Utilisation", 
        "Proactive Interface Input Utilisation", 
        "Proactive Interface Input Utilisation", 
        "Proactive Interface Output Utilisation", 
        "BGP Peer Down", 
        "Proactive Reachability", 
        "Proactive CPU", 
        "Proactive Response Time", 
        "Proactive Interface Output Utilisation", 
        "Proactive Memory Free", 
        "Proactive Interface Input Utilisation", 
        "BGP Peer Down", 
        "Proactive Interface Availability", 
        "Proactive Interface Input Utilisation", 
        "Proactive Interface Output Utilisation", 
        "Proactive Interface Output Utilisation", 
        "Proactive Reachability", 
        "Proactive Interface Output Utilisation", 
        "BGP Peer Down", 
        "Proactive Response Time", 
        "Proactive CPU", 
        "Proactive Interface Output Utilisation", 
        "Proactive Interface Input Utilisation", 
        "Proactive Memory Free", 
        "Proactive Interface Input Utilisation", 

    ]
}

/* 2 */
{
    "_id" : "GFS-INTERNET",
    "eventos" : [ 
        "Proactive Interface Output Utilisation", 
        "Proactive Interface Input Utilisation", 
        "Proactive Reachability", 
        "Proactive Response Time", 
        "Proactive CPU", 
        "Proactive Memory Free", 
        "Proactive Interface Output Utilisation", 
        "Proactive Interface Availability", 
        "Proactive Interface Input Utilisation", 
        "Proactive Interface Input Utilisation", 
        "Proactive Reachability", 
        "Proactive Interface Output Utilisation", 
        "Proactive Response Time", 
        "Proactive CPU", 
        "Proactive Interface Output Utilisation", 
        "Proactive Memory Free", 
        "Proactive Interface Input Utilisation", 
        "Proactive Interface Availability"
    ]
}