Answer the question
In order to leave comments, you need to log in
How to reorder documents in mongoDB?
Hello everyone, tell me pliz, how can I change the order of documents in mongoDB?
The server returns an array of this kind
[
{
"_id": "5eb003b825dddd2fc438fd0a",
"name": "Пицца Милано",
"category": "Пицца",
"price": 129,
"url": "https://www.pizzaking.ua/resizer/resize/upload/catalog/e/e7c6ce8e7bffbd7fc86a4c119262da24-472-472-c.jpg",
"description": "sfsfsdfssdsdfsd",
"__v": 0
},
{
"_id": "5eb004b03950840688b1834f",
"name": "Black Бургер",
"category": "Бургеры",
"price": 199,
"url": "https://ambar.net.ua/image/data/2398.jpg",
"description": "Самый сочный бургер",
"__v": 0
},
{
"_id": "5eb008c3f65282196c1a6c51",
"name": "Терамису",
"category": "Десерты",
"price": 55,
"url": "https://v.img.com.ua/b/orig/d/e8/12db2094c5da2d0c884f862c62c30e8d.jpg",
"description": "Нежное пироженое",
"__v": 0
}
]
Answer the question
In order to leave comments, you need to log in
Add an order field to the schema model and update this field. On the back, implement a default order based on this parameter, for example. Perhaps mongo has its own default sorter, you need to google it, but there must be a field based on which you need to sort
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question