Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4101

Mongoid sort by DateTime

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.1
    • Affects Version/s: None
    • Component/s: None
    • None

      Hello,
      It seems that sorting by datetime does not work with mongoid.

      I wanted to get the last time any User logged in:

      User.where(:current_sign_in_at.ne => nil).desc(:current_sign_in_at).limit(1).pluck(:current_sign_in_at)

      but since the result was wrong I inquired further and:

      [42] pry(main)> User.where(:current_sign_in_at.ne => nil).desc(:current_sign_in_at).entries.map(&:current_sign_in_at)
      => [Tue, 10 Mar 2015 13:05:57 CET +01:00,
      Fri, 10 Apr 2015 17:35:43 CEST +02:00,
      Thu, 18 Jun 2015 05:32:19 CEST +02:00,
      Mon, 22 Jun 2015 13:31:29 CEST +02:00,
      Wed, 13 May 2015 15:34:24 CEST +02:00,
      Fri, 19 Jun 2015 12:06:37 CEST +02:00,
      Fri, 19 Jun 2015 16:52:35 CEST +02:00,
      Tue, 16 Jun 2015 10:18:42 CEST +02:00,
      Fri, 19 Jun 2015 17:21:38 CEST +02:00,
      Wed, 17 Jun 2015 21:09:05 CEST +02:00,
      Wed, 27 May 2015 15:09:33 CEST +02:00,
      Wed, 10 Jun 2015 10:06:51 CEST +02:00,
      Wed, 27 May 2015 14:18:17 CEST +02:00,
      Fri, 29 May 2015 15:46:56 CEST +02:00,
      Fri, 29 May 2015 16:45:26 CEST +02:00,
      Mon, 22 Jun 2015 16:14:36 CEST +02:00]

      Version:

      bundle show mongoid
      => /home/muichkine/.rvm/gems/ruby-2.2.2/gems/mongoid-4.0.2

            Assignee:
            Unassigned Unassigned
            Reporter:
            muichkine Olivier Milla
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: