Module: Mongoid::Criterion::Creational
- Included in:
- Mongoid::Criteria
- Defined in:
- lib/mongoid/criterion/creational.rb
Overview
This module defines criteria behavior for creating documents in the database for specified conditions.
Instance Method Summary collapse
-
#create(attrs = {}) ⇒ Document
Create a document in the database given the selector and return it.
Instance Method Details
#create(attrs = {}) ⇒ Document
Create a document in the database given the selector and return it. Complex criteria, such as $in and $or operations will get ignored.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mongoid/criterion/creational.rb', line 21 def create(attrs = {}) klass.create( selector.inject(attrs) do |hash, (key, value)| hash.tap do |attrs| unless key.to_s =~ /\$/ || value.is_a?(Hash) attrs[key] = value end end end ) end |