how to work with multiple action and get count using mongodb?

前端 未结 1 452
感动是毒
感动是毒 2021-01-26 08:38

here i have create one query for the show count date wise in the chart. and i have used mongodb. and i have one object and in the object store multiple data and separate with on

相关标签:
1条回答
  • 2021-01-26 09:19

    Update first $match to

    {
      "$match": {
        "_id": ObjectId("595e3b2033961713940442cf"),
        "History.datetime": {
          "$lte": 1507529239000,
          "$gte": 1507012285558
        },
        "History.Action": {
          "$in": [
            "Comment",
            "like"
          ]
        }
      }
    }
    

    and second $match to

    {
      "$match": {
        "History.datetime": {
          "$lte": 1507529239000,
          "$gte": 1507012285558
        },
        "History.Action": {
          "$in": [
            "Comment",
            "like"
          ]
        }
      }
    }
    

    and $group to

    {
      "likecount": {
        "$sum": {
          "$cond": [
            {
              "$eq": [
                "$History.Action",
                "like"
              ]
            },
            1,
            0
          ]
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题