Method: MongoMapper::Document::ClassMethods#create

Defined in:
lib/mongo_mapper/document.rb

#create(doc_attributes) ⇒ Boolean #create(docs_attributes) ⇒ Boolean

Returns when a document is successfully created, true will be returned. If a document fails to create, false will be returned.

Examples:

Creating a single document

MyModel.create({ :foo => "bar" })

Creating multiple documents

MyModel.create([{ :foo => "bar" }, { :foo => "baz" })

Overloads:

  • #create(doc_attributes) ⇒ Boolean

    Create a single new document

    Parameters:

    • doc_attributes (Hash)

      key/value pairs to create a new document

  • #create(docs_attributes) ⇒ Boolean

    Create many new documents

    Parameters:

    • provide (Array<Hash>)

      many Hashes of key/value pairs to create multiple documents

Returns:

  • (Boolean)

    when a document is successfully created, true will be returned. If a document fails to create, false will be returned.



161
162
163
# File 'lib/mongo_mapper/document.rb', line 161

def create(*docs)
  initialize_each(*docs) { |doc| doc.save }
end