I have to retrieve the mongodb records in a sinatra app using Mongoid. For this I am trying to order the records retrieved using the following query:
@bin = Bin.find_by(bin_id: params[:bin_id]).order_by(:created_at.desc)
But I am getting the NoMethodError,
NoMethodError - undefined method `order_by' for #<Bin:0x00000101d24d60>: /Users/harshsingh/Documents/Codes/mogreet-requestbin/app.rb:79:in `block in <class:App>' /Users/harshsingh/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call' /Users/harshsingh/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!' /Users/harshsingh/.rvm/gems/ruby-2.1.2/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `' ...
I am not sure why the
order_by is not working, I tried looking into the Mongoid docs but couldn't find anything helpful to me.
Sorry I forgot to mention, I have an embedded document in the
Bin document called
Callback, with the relations
embeds_many :callbacks and
embedded_in :bin, :inverse_of => :bins, so I wanted to sort the
callbacks documents within one particular
bin based on