У меня 2 схемы. Именованный пользователь и друзья.
пользовательская схема выглядит следующим образом:
var userSchema = mongoose.Schema({
first_name: {type: String},
last_name: {type: String},
update_at: {type: Date}
})
Схема друзей выглядит следующим образом:
var userfollowersSchema = mongoose.Schema({
user_id: {type: String, ref: '"'User'"'},
friends_id: {type: String, ref: 'User'}
})
Я заполняю идентификатор друзей, используя запрос ниже. Мангуст
.populate('friends_id', '_id update_at', null, {sort: { 'update_at': -1 } })
Я также пробовал:
.populate({
path: 'friends_id',
select: ('_id update_at'),
options: {
sort: '-following_id.update_at'
}
})
Но он работает с _id. У меня есть результат:
[{
friends_id: {
update_at: Fri May 13 2016 15:46:43 GMT+0530 (India Standard Time),
count: 1,
_id: 5735a23168264e700b17e6ee
},
_id: 5735a2bb68264e700b17e6f2
}, {
friends_id: {
update_at: Fri May 13 2016 15:47:31 GMT+0530 (India Standard Time),
count: 0,
_id: 5735a24168264e700b17e6ef
},
_id: 5735a2c068264e700b17e6f3
}, {
friends_id: {
update_at: Fri May 13 2016 18:47:13 GMT+0530 (India Standard Time),
count: 2,
_id: 5735a25868264e700b17e6f0
},
_id: 5735a2c568264e700b17e6f4
}]
В: как отсортировать результаты заполнения по времени? Версия мангуста -
'"'мангуст'"': '"'^4.4.6'"',