0

I have below documents in Mongo DB:

{_id
666b07c615b7246
host
"SERVER1"
ip_address
"10.0.0.1"
status
"Running"
timestamp
2024-06-13-01-00-10}


{_id
666b07c615b7246
host
"SERVER2"
ip_address
"10.0.0.2"
status
"Down"
timestamp
2024-06-13-01-00-09}

and so on...

I want to get the count of SERVER1 and When it is in Running status.

I am using below query:

mycollection.server-status.aggregate([
  {
    $project:
      /**
       * query: The query in MQL.
       */
 
      {
        _id: 0,
        host: 1,
        status: 1,
        timestamp: 1,
      }
  },
  {
    $match:
      /**
       * query: The query in MQL.
       */
      {
        status: "Running"
      }
  }
])

I am getting multiple rows, but i want a single row to be displayed at a time which contains Server and its status and also count. But i want to find the details of each Unique server and its count and Display like below:

SERVER1 Running 4

Where 4 is the number of Documents which contain SERVER1 as Running.

Please Note: Timestamp is unique in each document or row.

2

0