lib/mongoid/factory.rb
def from_db(klass, attributes = nil, criteria_instance_id = nil)
      type = (attributes || {})["_type"]
      if type.blank?
        klass.instantiate(attributes, criteria_instance_id)
      else
        type.camelize.constantize.instantiate(attributes, criteria_instance_id)
      end
    end
# Builds a new +Document+ from the supplied attributes loaded from the
# database.
#
# @example Build the document.
#   Mongoid::Factory.from_db(Person, { "name" => "Durran" })
#
# @param [ Class ] klass The class to instantiate from if _type is not present.
# @param [ Hash ] attributes The document attributes.
#
# @return [ Document ] The instantiated document.
Builds a new +Document+ from the supplied attributes loaded from the
database.
Builds a new + Document + from the supplied attributes loaded from the database .
def from_db(klass, attributes = nil, criteria_instance_id = nil)
      type = (attributes || {})["_type"]
      if type.blank?
        klass.instantiate(attributes, criteria_instance_id)
      else
        type.camelize.constantize.instantiate(attributes, criteria_instance_id)
      end
    end
def from_db ( klass , attributes = nil , criteria_instance_id = nil ) type = ( attributes || { } ) [ "_type" ] if type . blank? klass . instantiate ( attributes , criteria_instance_id ) else type . camelize . constantize . instantiate ( attributes , criteria_instance_id ) end end
Builds a new +Document+ from the supplied attributes loaded from the
database.
Builds a new + Document + from the supplied attributes loaded from the database .
The instantiated document.
The instantiated document .
 Document 
klass
attributes
criteria_instance_id
attributes The document attributes.
attributes The document attributes .
example
Build the document. Mongoid::Factory.from_db(Person, { "name" => "Durran" })
Build the document . Mongoid :: Factory . from_db ( Person { " name " = > " Durran " } )