mongoid / origin

A Ruby DSL for building MongoDB queries
http://mongoid.org/en/origin/index.html
MIT License
62 stars 29 forks source link

'.not' isn't negating query #41

Closed aaronpanch closed 12 years ago

aaronpanch commented 12 years ago

I'm sorry to bother, but I'm not sure if I am missing some of the Mongoid/Origin functionality. I'm trying to run a negation on a '.where' query but it doesn't seem to produce a negated result. I have a model called user:

class User
  include Mongoid::Document
  field :userid
  field :fname
  field :lname
end

However when I attempt to query from the Rails console

User.not.where(fname: "Aaron").selector
 => {"fname"=>"Aaron"}

User.where(fname: "Aaron").selector
 => {"fname"=>"Aaron"} 

And it seems as if the selector isn't producing the expected { "$not" => { "fname" => "Aaron" }} result for negation. Am I missing something? Or do I have a faulty setting? I'm running mongoid (3.0.1), moped (1.1.5), and origin (1.0.4).

Thanks!

durran commented 12 years ago

Not missing anything, I would expect this it negate it.

durran commented 12 years ago

Sorry I was wrong - the behaviour is correct since $not can only affect other operators - so not in a normal query. From the docs:

"The $not meta operator can only affect other operators."

http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-Metaoperator%3A{{%24not}}