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

$not not applied to equality

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.7
    • Affects Version/s: None
    • Component/s: None
    • None

      What am I doing wrong? This seems pretty basic. As in taken-from-origin-example basic.

      #!/usr/bin/env ruby
      
      require "mongoid"
      
      Mongoid.configure do |config|
        config.connect_to "mongoid_test"
      end
      
      class A
        include Mongoid::Document
      
        field :name, type: String, default: "Dave"
      end
      
      A.delete_all
      
      A.create
      A.create
      A.create
      A.create name: "David"
      A.create name: "Tom"
      
      # `not` does not work for simple equality
      # contrary to example from http://mongoid.org/en/origin/docs/selection.html
      puts A.where(name: "Dave").map(&:name).join " "
      puts A.not.where(name: "Dave").map(&:name).join " "
      puts A.not.where(name: "Dave").selector.inspect
      puts A.where(:name.ne => "Dave").map(&:name).join " "
      puts A.where(:name => /^Dav/).map(&:name).join " "
      puts A.not.where(:name => /^Dav/).map(&:name).join " "
      

      Output:

      Dave Dave Dave
      Dave Dave Dave # should be David Tom
      {"name"=>"Dave"} # should be { "$not" => { "name" => "Dave" }}
      David Tom
      Dave Dave Dave David
      Dave Dave Dave David # should be Tom
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            amw Adam Wróbel
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: