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

$not not applied to equality

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.0.7
    • Component/s: None
    • Labels:
      None

      Description

      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

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: