Method: Mongoid::Criterion::Exclusion#excludes
- Defined in:
- lib/mongoid/criterion/exclusion.rb
#excludes(attributes = {}) ⇒ Object
Adds a criterion to the Criteria that specifies values that are not allowed to match any document in the database. The MongoDB conditional operator that will be used is “$ne”.
Options:
attributes: A Hash where the key is the field name and the value is a value that must not be equal to the corresponding field value in the database.
Example:
criteria.excludes(:field => "value1")
criteria.excludes(:field1 => "value1", :field2 => "value1")
Returns: self
21 22 23 24 25 |
# File 'lib/mongoid/criterion/exclusion.rb', line 21 def excludes(attributes = {}) mongo_id = attributes.delete(:id) attributes = attributes.merge(:_id => mongo_id) if mongo_id update_selector(attributes, "$ne") end |