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

Range as field-level operator argument generates bogus queries

    XMLWordPrintable

Details

    • Bug
    • Status: Backlog
    • Trivial - P5
    • Resolution: Unresolved
    • None
    • None
    • Query

    Description

      Mongoid has a handy shortcut to convert Range objects to a $gte/$lte pair:

      irb(main):070:0> job.tasks.where(hour: 10..15)
      => 
      #<Mongoid::Criteria
        selector: {"hour"=>{"$gte"=>10, "$lte"=>15}}
        options:  {}
        class:    Task
        embedded: true>
      
      

      Unfortunately, when the Range object is an argument of a field-level operator, the result is a bogus query:

      irb(main):071:0> job.tasks.where(hour: {'$eq':10..15})
      => 
      #<Mongoid::Criteria
        selector: {"hour"=>{:$eq=>{"$gte"=>10, "$lte"=>15}}}
        options:  {}
        class:    Task
        embedded: true>
      

      The latter case should ideally be detected and raise an exception during query construction.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: