Class: Mongoid::Persistence::Operations::Insert

Inherits:
Object
  • Object
show all
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

#conflicts, #document

Instance Method Summary collapse

Methods included from Insertion

#prepare

Methods included from Mongoid::Persistence::Operations

#collection, #deletes, #initialize, insert, #inserts, #notifying_parent?, #options, #parent, remove, #selector, update, #updates, #validating?

Instance Method Details

#persistDocument

Insert the new document in the database. This delegates to the standard MongoDB collection’s insert command.

Examples:

Insert the document.

Insert.persist

Returns:

  • (Document)

    The document to be inserted.



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, options)
    IdentityMap.set(doc)
  end
end