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

Range as field-level operator argument generates bogus queries

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: Query

      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.

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

              Created:
              Updated: