I have a simple model:
user = {
'items': [{
'name': 'abc',
'pages': [ObjectId("58c703a353dbaf37586b885c"), ObjectId("58c703a353dbaf37586b885d"), ..]}
}]
};
I'm trying to sort the pages of current item:
User.findOne({'_id': id}, {'items': {$elemMatch: {'_id': id2}}})
.populate({path: 'items.pages', select: '_id', options: { sort: { _id: -1 } }})
.exec(function(err, user) {
});
But I'm getting an error: Error: Cannot populate with
sorton path items.pages because it is a subproperty of a document array
. What should I change?