пользователь (документ mongodb)
{
"_id": "5bccfb7515bc6d0c6872ed91",
"notification": {
"notidata": [
{
"data": {
"para": "Your Ad '1' has been successfully submitted."
},
"notistatus": false,
"_id": "5be35d89113aec40c4ca7517",
"notidate": "2018-11-07T21:47:53.803Z"
},
{
"data": {
"para": "Your Ad '2' has been successfully submitted."
},
"notistatus": false,
"_id": "5be35d92113aec40c4ca7519",
"notidate": "2018-11-07T21:48:02.729Z"
}
],
"counter": 4
},
"ads": [],
"username": "mesam",
"email": "mesam@hotmal.com",
"password": "0",
"country": "AZE",
"createdOn": "2018-10-21T22:19:33.377Z",
"__v": 0
}
route.js
User.findOneAndUpdate({ _id: user._id }, { $push: { "notification.notidata": { "data.para": "Your Ad " + "'" + thisad.heading + "'" + " has been successfully submitted."} } }, { new: true }, function (err, df) { ....
Я хочу, чтобы notidata
было отсортировано по notidate
. Использование $postion: 0
не сработало. И не сделал $sort: notidate: -1
* неудачная попытка позиции $ *
User.findOneAndUpdate({ _id: user._id }, { $push: { "notification.notidata": { "data.para": "Your Ad " + "'" + thisad.heading + "'" + " has been successfully submitted.", "$position": 0} } }, { new: true }, function (err, df) {....
неудачная попытка сортировки $
User.findOneAndUpdate({ _id: user._id }, { $push: { "notification.notidata": { "data.para": "Your Ad " + "'" + thisad.heading + "'" + " has been successfully submitted.", "$sort": {"notification.notidata.notidate": -1}} } }, { new: true }, function (err, df) {....