Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
How to Sort Mongo collection in F#

I can get a collection in MongoDB using F# No problem using

let draws = db.GetCollection<Draw>("draws").Find(fun _ -> true)

To Sort I would expect it to be:

let draws = db.GetCollection<Draw>("draws").Find(fun _ -> true).Sort(Builders<Draw>.Sort.Descending(d => d.drawDate))

But I am getting the following error. In the intellisense all of the types seem to be recognised all the way through so I am not sure what to do.

A unique overload for method 'Descending' could not be determined based on type information prior to this program point. A type annotation may be needed.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Your second lambda is using C# syntax. I'm not sure if that's what's causing the compiler error, but I think it's easier to do something like this anyway:

let draws =
    db.GetCollection<Draw>("draws")
        .Find(fun _ -> true)
        .SortByDescending(fun d -> d.drawDate :> obj)

(Note that the SortByDescending function requires a result of explicit type object, but it shouldn't cause any problems for you. I think this is because the driver was created with C# clients in mind, where the upcast is implicit.)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!