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

Document implemented symbol operator names including deviations

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Docs, Query
    • None

      Mongoid permits operators to be called on symbols for convenience, e.g.:

      (byebug) MyModel.any_of(:field.lte => 'x')
      #<Mongoid::Criteria
        selector: {"field"=>{"$lte"=>"x"}}
        options:  {}
        class:    MyModel
        embedded: false>
      

      There are implemented operators that use different names from the MongoDB's ones to avoid conflicts with Ruby methods, which are type and size:

      (byebug) MyModel.any_of(:field.type => 'x')
      *** NoMethodError Exception: undefined method `type' for :field:Symbol
      
      nil
      (byebug) MyModel.any_of(:field.with_type => 'x')
      #<Mongoid::Criteria
        selector: {"field"=>{"$type"=>"x"}}
        options:  {}
        class:    MyModel
        embedded: false>
      (byebug) MyModel.any_of(:field.size => 1)
      *** NoMethodError Exception: undefined method `__expr_part__' for 5:Integer
      Did you mean?  __expand_complex__
      
      nil
      (byebug) MyModel.any_of(:field.with_size => 1)
      #<Mongoid::Criteria
        selector: {"field"=>{"$size"=>1}}
        options:  {}
        class:    MyModel
        embedded: false>
      

      The deviations should be documented.

      The symbol operators which are supported aren't documented either, this should also be done - the list of operators in the server is https://docs.mongodb.com/manual/reference/operator/query/

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

              Created:
              Updated: