Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 0.26 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Is there a way to put all the nil value at the end when sorting with mongodb/mongoid?
  2. People.asc(:age)
  3.        
  4. nils, not_nils = People.asc(:age).partition { |p| p.age.nil? }
  5. people = not_nils + nils
  6.        
  7. People.desc(:age)
  8.        
  9. People.not_in(:age, [nil]).asc(:age)