orlandos-nl / MongoKitten

Native MongoDB driver for Swift, written in Swift

Home Page:https://orlandos.nl/docs/mongokitten/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sort not working with generated fields

burf2000 opened this issue · comments

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

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

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?

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