How to keep the original sort in distinct.

41 views
Skip to first unread message

Larry Zhao

unread,
Jun 13, 2012, 8:42:21 AM6/13/12
to mon...@googlegroups.com
Dear guys,

I have the following model:

class Message
  include Mongoid::Document
  include Mongoid::Timestamps

  field :conversation_id, :type => String
end

So if I do:
Message.all.order_by(:created_at, :desc).distinct(:conversation_id)

I am hoping that the array which contains ``conversation_id``s could preserve the order from the result of ``Message.all.order_by(:created_at, :desc)`` But as I tested, it seems that the result of distinct will is in an order like (:id, :asc). Is there a recommended way to do that? 



Cheers,

--- 
Larry Zhao

Durran Jordan

unread,
Jun 13, 2012, 10:58:27 AM6/13/12
to mon...@googlegroups.com
Unfortunately no at the moment. The distinct command does not take any order options. There is an open issue: https://jira.mongodb.org/browse/SERVER-2130

2012/6/13 Larry Zhao <thehidd...@gmail.com>
Reply all
Reply to author
Forward
0 new messages