0

I have a document in mongodb and do a search with the medoto .find () mongoose it returns the following answer and I need to order a subdocument

Order by listCart for clienId

{
"success": true,
"data": [
    {
        "deleted": false,
        "_id": "5ec4692f18b52a76bb2f278a",
        "userId": "5ea8abe5d57e5a256bc25140",
        "listCart": [//document order by clienId
            {
                "ppt": 2,
                "_id": "5ec4692f18b52a76bb2f278b",
                "topId": "5ea8ac05792ded26bdc4ece1",
                "clienId": "5ea8abe5d57e5a256bc00001"
            },
            {
                "ppt": 2,
                "_id": "5ec4692f18b52a76bb2f278c",
                "topId": "5ea8b439837acd35425fea02",
                "clienId": "5ea8abe5d57e5a256bc00002"
            },
            {
                "ppt": 2,
                "_id": "5ec4692f18b52a76bb2f278d",
                "topId": "5ea8ac05792ded26bdc4ece3",
                "clienId": "5ea8abe5d57e5a256bc00001"
            },
            {
                "ppt": 2,
                "_id": "5ec4692f18b52a76bb2f278e",
                "topId": "5ea8b439837acd35425fea04",
                "clienId": "5ea8abe5d57e5a256bc00002"
            }
        ],
        "createdAt": "2020-05-19T23:18:07.345Z",
        "updatedAt": "2020-05-19T23:18:07.345Z",
        "__v": 0
    }
],
"message": "Request successful"

}

Thank you

andres henao
  • 21
  • 1
  • 4
  • 1
    Does this answer your question? [how to sort array inside collection record in mongoDB](https://stackoverflow.com/questions/13449874/how-to-sort-array-inside-collection-record-in-mongodb) As given there you need to `$unwind` data & listCart sort by `clienId` & group back the arrays.. – whoami - fakeFaceTrueSoul May 20 '20 at 01:54
  • 1
    Hi, the answer is perfect thanks – andres henao May 25 '20 at 18:57

0 Answers0