I am using mongoose and I want to sort an array of objects by a key "position". In my array the objects "position" is: 0, 1 , 3, 2. I want to sort them by the "position".
"images": [
{
"_id": {
"$oid": "5bcf24f8b639a936d5471b04"
},
"position": 0,
"name": "1540302062678adidas-fashion-feet-1225136.jpg",
"created_at": {
"$date": "2018-10-23T13:41:13.000Z"
}
},
{
"_id": {
"$oid": "5bcf24f8b639a936d5471b05"
},
"position": 1,
"name": "1540302064570adult-agency-business-380769.jpg",
"created_at": {
"$date": "2018-10-23T13:41:13.000Z"
}
},
{
"_id": {
"$oid": "5bcf24f8b639a936d5471b07"
},
"position": 3,
"name": "1540302067059adult-body-businessman-652347.jpg",
"created_at": {
"$date": "2018-10-23T13:41:13.000Z"
}
},
{
"_id": {
"$oid": "5bcf24f8b639a936d5471b06"
},
"position": 2,
"name": "1540302066875adult-beard-blurred-background-936072.jpg",
"created_at": {
"$date": "2018-10-23T13:41:12.000Z"
}
}
]