Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordering by custom field is not working #372

Open
ivanflashacademy opened this issue Mar 17, 2024 · 0 comments
Open

Ordering by custom field is not working #372

ivanflashacademy opened this issue Mar 17, 2024 · 0 comments

Comments

@ivanflashacademy
Copy link

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
@ivanflashacademy ivanflashacademy changed the title Ordering by custom field does not working Ordering by custom field is not working Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant