jeudi 19 juillet 2018

sum key and group by key with Mongodb and Laravel

Having this collection -

{
    "_id": "5b508587de796c0006207fa7",
    "id": "1",
    "status": "pending",        
    "updated_at": "2018-07-19 13:02:40",
    "created_at": "2018-07-19 12:35:19"
},
{
    "_id": "5b508587de796c0006207fa5",
    "id": "2",
    "status": "completed",        
    "updated_at": "2018-07-19 13:02:40",
    "created_at": "2018-07-19 12:35:19"
},

I want to have a query that will sum the status key by the id key.

For example -

{
  "id":"1",
  "pending":"1"
}

I am using Laravel 5.5 with MongoDB



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire