Class: Mongoid::Persistence::Operations::Insert
- Includes:
- Insertion, Mongoid::Persistence::Operations
- Defined in:
- lib/mongoid/persistence/operations/insert.rb
Overview
Insert is a persistence command responsible for taking a document that has not been saved to the database and saving it.
The underlying query resembles the following MongoDB query:
collection.insert(
{ "_id" : 1, "field" : "value" },
false
);
Instance Attribute Summary
Attributes included from Mongoid::Persistence::Operations
Instance Method Summary collapse
-
#persist ⇒ Document
Insert the new document in the database.
Methods included from Insertion
Methods included from Mongoid::Persistence::Operations
#collection, #deletes, #initialize, insert, #inserts, #notifying_parent?, #options, #parent, remove, #selector, update, #updates, #validating?
Instance Method Details
#persist ⇒ Document
Insert the new document in the database. This delegates to the standard MongoDB collection’s insert command.
25 26 27 28 29 30 |
# File 'lib/mongoid/persistence/operations/insert.rb', line 25 def persist prepare do |doc| collection.insert(doc.as_document, ) IdentityMap.set(doc) end end |