yii2-mongodb
yii2-mongodb copied to clipboard
Ordering by custom field is not working
Hi everyone!
What steps will reproduce the problem?
I encountered a problem when I needed to order my collection list by custom column For instance I add a custom column to my query with method select
$query->select(['customColumn' => ['$size' => '$items']])
// and then I need to order by this custom column
$query->addOrderBy(['customColumn' => SORT_DESC])
And nothing happens PS I have already tried 1 and -1 instead of using SORT_ASC and SORT_DESC
What's expected?
I expect same behaviour when I use $project
or $addField
parameters in native query
Actually this works fine
$collecion->aggregate([
[
'$project' => [
'customColumn' => ['$size' => '$items'],
]
],
[
'$sort' => ['customColumn' => -1]
],
])
I would like you to add a couple of methods for $project
$query->projects([...])
$query->addProject([...])
Or add existing fields to $project
What do you get instead?
Nothing
Additional info
Q | A |
---|---|
Yii version | |
Yii MongoDB version | |
MongoDB server version | |
PHP version | |
Operating system |