I need some assistance.
Is there a way to organize the items I input to the Model via .populate based on a specific variable in the data?
The information I receive looks like this:
"items": [
{
"_id": "xxxx",
"name": "Item 1",
"price": 4000,
"order": 2,
"user": {
"_id": "xxxx",
}
},
{
"_id": "xxxx",
"name": "Item 2",
"price": 4000,
"order": 1,
"user": {
"_id": "xxxx",
}
}
],
I am looking to have them organized by the order
variable.
For instance, Item 1 should be second and Item 2 first.
If an item does not include the order
field, it should go at the end of the list.