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

Does Mongoid support order_by?

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 7.0.5
    • Component/s: Query
    • None
    • Environment:
      OSX 10.13.6
      Mongo: db version v3.6.2
      mongo gem 2.10.2

      I searched the docs and there is no mention of order_by or sort (except default sort by _id).

      https://docs.mongodb.com/mongoid/current/tutorials/mongoid-queries/#id1

       

      Is it possible that Mongoid no longer supports order_by?

       

      I found this documentation but not sure if is applicable:

      https://www.rubydoc.info/github/mongoid/origin/Origin%2FOptional:order_by

       

      Putting docs aside, it seems that order_by does not work.

       

      ap Category.order_by(created_at: :asc).pluck(:name, :created_at)
      [
      {{ [0] [}}
      {{ [0] "computers",}}
      {{ [1] 2019-10-09 02:43:35 UTC}}
      {{ ],}}
      {{ [1] [}}
      {{ [0] "cosmetics",}}
      {{ [1] 2019-11-09 18:43:26 UTC}}
      {{ ],}}
      {{ [2] [}}
      {{ [0] "electronics",}}
      {{ [1] 2019-10-09 02:43:35 UTC}}
      {{ ],}}

       

       

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            george@boost-media.com George Ulmer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: