sql >> Base de Datos >  >> NoSQL >> MongoDB

¿Cómo trabajar con acciones múltiples y contar usando mongodb?

Actualizar primero $match a

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

y segundo $match a

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

y $group a

{
  "likecount": {
    "$sum": {
      "$cond": [
        {
          "$eq": [
            "$History.Action",
            "like"
          ]
        },
        1,
        0
      ]
    }
  }
}