-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Query
-
None
When `not` is given simple hashes, Mongoid trivially negates them with $not but the server does not support this syntax:
irb(main):001:0> Band.not(name: 'test') => #<Mongoid::Criteria selector: {"name"=>{"$not"=>"test"}} options: {} class: Band embedded: false> irb(main):002:0> Band.not(name: 'test').to_a Traceback (most recent call last): 2: from (irb):2 1: from (irb):2:in `to_a' Mongo::Error::OperationFailure ($not needs a regex or a document (2) (on localhost:14420, attempt 1))
Mongoid constructs working queries when not negates the next condition:
irb(main):004:0> Band.not.where(name: 'test') => #<Mongoid::Criteria selector: {"name"=>{"$ne"=>"test"}} options: {} class: Band embedded: false> irb(main):005:0> Band.not.where(name: 'test').to_a => [#<Band _id: 5dc9f7d5ce4ef34893354323, name: "Sun Project", description: "Sun\nProject">]