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

Sort not working with generated fields #152

Closed
burf2000 opened this issue Feb 12, 2018 · 3 comments
Closed

Sort not working with generated fields #152

burf2000 opened this issue Feb 12, 2018 · 3 comments

Comments

@burf2000
Copy link

burf2000 commented Feb 12, 2018

let query: Query = [
            "$text": ["$search": "ebay" ],
            "lang" : ["$eq": "en"],
        ]
        
let projection: Projection = [
             "_id": .excluded,
            "url": "url",
            "score": ["$meta" : "textScore"]
        ]
    
let sort : Sort = [
            "score": .descending
        ]
        
        let matchingEntities: CollectionSlice<Document> = try pages.find(query, sortedBy: sort, projecting: projection)

So, this query generates the textscore as score however I cant sort on it. If it do $score in the sort it fails

@Joannis
Copy link
Member

Joannis commented Feb 12, 2018

This is not a MongoKitten issue. MongoDB sees $score as an operator of sorts, or a reference to another key.

@burf2000
Copy link
Author

burf2000 commented Feb 13, 2018

I can run the following on Mongo fine:

db.pages.find( {$and: [{$text: {$search: "ebay"}} , {"lang" : "en"} ] }, {score: {$meta: "textScore"}}).sort({score:{$meta:"textScore"}})

How would I do the same using MongoKitten?

@burf2000
Copy link
Author

Hey @Joannis any chance you can help me with this as you wrote the framework, I asked on Slack, Stackoverflow etc. There seems to be very little documentation on sort

@Joannis Joannis closed this as completed May 2, 2020
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

2 participants