Book Image

Learning Mongoid

By : Gautam Rege
Book Image

Learning Mongoid

By: Gautam Rege

Overview of this book

Mongoid helps you to leverage the power of schema-less and efficient document-based design, dynamic queries, and atomic modifier operations. Mongoid eases the work of Ruby developers while they are working on complex frameworks. Starting with why and how you should use Mongoid, this book covers the various components of Mongoid. It then delves deeper into the detail of queries and relations, and you will learn some tips and tricks on improving performance. With this book, you will be able to build robust and large-scale web applications with Mongoid and Rails. Starting with the basics, this book introduces you to components such as moped and origin, and how information is managed, learn about the various datatypes, embedded documents, arrays, and hashes. You will learn how a document is stored and manipulated with callbacks, validations, and even atomic updates. This book will then show you the querying mechanism in detail, right from simple to complex queries, and even explains eager loading, lazy evaluation, and chaining of queries. Finally, this book will explain the importance of performance tuning and how to use the right indexes. It also explains MapReduce and the Aggregation Framework.
Table of Contents (14 chapters)
Learning Mongoid
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Index

A

  • -after_add option / :before_add, :after_add, :before_remove, and :after_remove
  • -after_remove option / :before_add, :after_add, :before_remove, and :after_remove
  • -all / Query selectors
  • -allow_destroy object / Nested attributes
  • -as option / Relation-specific options
    • about / :as
  • -autobuild
    • about / :autobuild
  • -autobuild option / Relation-specific options
  • -autosave option / Relation-specific options
    • about / :autosave
  • accepts_neste_attributes_for
    • URL / Nested attributes
  • ActiveModel scopes
    • about / Scopes
  • ActiveModel validations / Validations
  • Acts as state machine (aasm)
    • about / Acts as state machine (aasm)
    • carrierwave / carrierwave
    • mongoid-audit / mongoid-audit
    • devise / devise
  • aggregation framework
    • about / The aggregation framework
    • and MapReduce / MapReduce and the aggregation framework
    • using / Using the aggregation framework
    • and MapReduce, selecting between / Choosing between MapReduce and the aggregation framework
  • arrays
    • about / Arrays and hashes
    • queries / Queries on arrays and hashes
  • Atomic attribute updates
    • about / Atomic attribute updates
  • atomic modifiers
    • about / Atomic modifiers
    • find_and_modify / find_and_modify
  • attributes
    • mass assignment / Mass assignment and security
    • updating / Updating documents and attributes
  • attr_accessible or attr_protected / Mass assignment and security

B

  • -before_add option / :before_add, :after_add, :before_remove, and :after_remove
  • -before_remove option / :before_add, :after_add, :before_remove, and :after_remove
  • BasicCursor function / Querying with indexed fields
  • belongs_to relation
    • about / The belongs_to relation
    • $index option / :index
    • $polymorphic option / :polymorphic
    • $touch option / :touch
    • $counter_cache option / :counter_cache
  • BigDecimal data type / Origins of Origin
  • Binary JSON (BSON)
    • about / Binary JSON (BSON)
  • Binary Tree / Querying with indexed fields
  • BSON format / The Mongoid document
  • BTreeCursor / Querying with indexed fields

C

  • -cascaded_callbacks option / Relation-specific options
  • -cascade_callbacks option / :cascade_callbacks
  • -class_name option / Common options for all relations
    • about / :class_name
  • -counter_cache option / Relation-specific options, :counter_cache
  • -cyclic option / Relation-specific options, :cyclic
  • callbacks
    • about / Callbacks
    • URL / Callbacks
  • carrierwave / carrierwave
  • Category object / :inverse_of
  • compound index / Compound index
  • covered queries
    • about / Covered queries

D

  • -delete value / :dependent
  • -dependent option / Relation-specific options
    • about / :dependent
    • $delete value / :dependent
    • $destroy value / :dependent
    • $nullify value / :dependent
    • $restrict value / :dependent
  • -destroy value / :dependent
  • date attributes
    • about / Date and time attributes
  • delayed sync / Memory maps, delayed sync, and journals
  • deserialize method / Serialization with Mongoize
  • devise / devise
  • distanceMultiplier operator / Geolocation queries
  • dynamic attributes
    • about / Dynamic attributes, Dynamic attributes

E

  • -each / Mongoid criteria
  • -elem_match / Query selectors
  • -exists / Query selectors
  • -exists? / Mongoid criteria
  • -extend option / Common options for all relations
  • eager loading / n+1 query problem and eager loading
  • embedded documents
    • about / Embedded documents
  • embedded_in method
    • about / embedded_in – resolving children
  • embedded_in relation / Embedded documents, Embedded polymorphic relations
  • embeds_many method
    • about / embeds_many – embedding many documents
    • $cascade_callbacks option / :cascade_callbacks
    • $store_as option / :store_as
    • $cyclic option / :cyclic
  • embeds_one method
    • about / embeds_one – embed one document
  • evolve method / Serialization with Mongoize

F

  • -find / Mongoid criteria
  • -find_and_modify / find_and_modify
  • -find_by / Mongoid criteria
  • -find_or_create_by / Mongoid criteria
  • -find_or_initialize_by / Mongoid criteria
  • -first / Mongoid criteria
  • -first_or_create / Mongoid criteria
  • -first_or_create! / Mongoid criteria
  • -first_or_initialize / Mongoid criteria
  • -following relation / :inverse_of
  • -foreign_key option / Relation-specific options
    • about / :foreign_key
  • field aliases
    • about / Field aliases
  • findAndModify method / The MongoDB findAndModify method
  • find_and_modify
    • about / find_and_modify
  • find_and_modify action / Updating documents and attributes
  • finite-state machine (FSM)
    • about / Acts as state machine (aasm)
  • follower_ids object / :inverse_of

G

  • $geoNear / Geolocation queries, Choosing between MapReduce and the aggregation framework
  • $group / Choosing between MapReduce and the aggregation framework
  • %gt/%gte/%lt/%lte / Query selectors
  • Gemfile / Setting up Sodibee
  • Geolocation
    • about / Geolocation queries
  • geo_near method / Geolocation queries

H

  • hashed index / Hashed index
  • hashes
    • about / Arrays and hashes
    • queries / Queries on arrays and hashes
  • has_and_belongs_to_many relation
    • about / has_and_belongs_to_many – the many-to-many relation
    • $inverse_of option / :inverse_of
  • has_many method
    • about / has_many – the many-to-one relation
    • $order option / :order
    • Topicnorder option / :order
    • $after_remove option / :before_add, :after_add, :before_remove, and :after_remove
    • $before_add option / :before_add, :after_add, :before_remove, and :after_remove
    • $before_remove option / :before_add, :after_add, :before_remove, and :after_remove
    • $after_add option / :before_add, :after_add, :before_remove, and :after_remove
  • has_one method
    • about / has_one – the one-to-one relation
    • $as option / :as
    • $autosave option / :autosave
    • $autobuild option / :autobuild
    • $dependent option / :dependent
    • $primary_key option / :primary_key
    • $foreign_key option / :foreign_key
    • $validate option / :validate

I

  • -in / Query selectors
  • -index option / Relation-specific options, :index
  • -inverse_class_name option / Common options for all relations
  • -inverse_of option / Common options for all relations, :inverse_of
    • about / :inverse_of
  • IdentityMap
    • about / IdentityMap
    • n+1 query problem / n+1 query problem and eager loading
    • eager loading / n+1 query problem and eager loading
  • inc method / Atomic attribute updates
  • indexed fields
    • querying with / Querying with indexed fields
  • indexes
    • about / Indexes
    • creation, options / Indexes
    • write concern / Write concern
    • writie concern / Write concern
    • compound index / Compound index
    • multikey index / Multikey index
    • hashed index / Hashed index
    • text indexes / Text index
  • inverse_of method / :inverse_of
  • inverse_of option / :inverse_of, :cyclic

J

  • journals / Memory maps, delayed sync, and journals

L

  • $limit / Choosing between MapReduce and the aggregation framework
  • -last / Mongoid criteria
  • -limit object / Nested attributes
  • localization
    • about / Localization
  • lock versioning / Applications and lock versioning

M

  • $match / The aggregation framework, Choosing between MapReduce and the aggregation framework
  • MapReduce
    • and aggregation framework / MapReduce and the aggregation framework
    • and aggregation framework, selecting between / Choosing between MapReduce and the aggregation framework
  • mass assignment
    • of attributes / Mass assignment and security
    • attr_protected / Mass assignment and security
    • attr_accessible / Mass assignment and security
    • strong_parameters / Mass assignment and security
    • resolving / Mass assignment and security
  • memory maps
    • about / Memory maps, delayed sync, and journals
  • models
    • creating / Creating models
    • testing / Testing the models
  • modules, Mongoid
    • timestamping / Timestamping
    • versioning / Versioning
    • Paranoia / Paranoia
    • Acts as state machine (aasm) / Acts as state machine (aasm)
  • MongoDB
    • findAndModify method / The MongoDB findAndModify method
    • aggregation framework / The aggregation framework
    • profiling / Profiling MongoDB
  • MongoDB environment
    • about / MongoDB environment
  • MongoDB version
    • about / MongoDB version
  • Mongoid
    • and MongoMapper / Mongoid and MongoMapper
    • Symbol class, overloading / Overloading the Symbol class
    • ActiveModel scopes / Scopes
  • Mongoid$$Criteria / Serialization with Mongoize
  • Mongoid$$Criteria module / Mongoid criteria
  • Mongoid$$Errors$$MixedRelations error / Embedded documents
  • Mongoid$$Extensions / Serialization with Mongoize
  • mongoid-audit / mongoid-audit
  • Mongoid 2.x
    • about / Notice about Mongoid 2.x
  • Mongoid criteria
    • about / Mongoid criteria
  • Mongoid document
    • about / The Mongoid document
    • attributes / Basic attributes
    • arrays / Arrays and hashes
    • hashes / Arrays and hashes
    • date and time attributes / Date and time attributes
    • serializing with / Serialization with Mongoize
    • Field aliases / Field aliases
    • embedded / Embedded documents
    • processing / MongoDB persistence strategy
    • creating / Creating documents
    • updating / Updating documents and attributes
    • database locks / Database locks and transactions
    • transactions / Database locks and transactions
    • lock versioning / Applications and lock versioning
  • MongoMapper
    • and Mongoid / Mongoid and MongoMapper
    • about / Embedded documents
  • Moped
    • about / Introducing Moped
  • multikey index / Multikey index

N

  • -name option / Common options for all relations
  • -near / Query selectors
  • -near_sphere / Query selectors
  • -nin / Query selectors
  • -nullify value / :dependent
  • nested attributes
    • about / Nested attributes
  • nreturned expression / Monitoring query performance
  • nsanned expression / Monitoring query performance
  • nscanned parameter / Profiling MongoDB
  • ntoreturn expression / Monitoring query performance
  • numYields expression / Monitoring query performance

O

  • -order option / Relation-specific options
  • origin
    • about / Origins of Origin
  • Origin
    • about / Introducing Origin

P

  • $project / The aggregation framework, Choosing between MapReduce and the aggregation framework
  • -polymorphic option / Relation-specific options, :polymorphic
  • -primary_key option / Relation-specific options
    • about / :primary_key
  • params hash / Mass assignment and security
  • Paranoia module
    • about / Paranoia
  • pluck object / Mongoid criteria
  • Polymorphic relations
    • about / Polymorphic relations
    • embedded / Embedded polymorphic relations

Q

  • query expression / Monitoring query performance
  • query performance
    • monitoring / Monitoring query performance
    • statistical data, finding / Statistical data
    • Hint and currentOp / Hint and currentOp
  • query selectors
    • about / Query selectors
    • Topicnall / Query selectors
    • Topicnexists / Query selectors
    • %gt/%gte/%lt/%lte / Query selectors
    • Topicnin / Query selectors
    • Topicnnin / Query selectors
    • Topicnelem_match / Query selectors
    • Topicnnear / Query selectors
    • Topicnnear_sphere / Query selectors
    • Topicnwithin_box / Query selectors
    • Topicnwithin_circle / Query selectors
    • Topicnwithin_spherical_circle / Query selectors
    • Topicnwithin_polygon / Query selectors
  • { $query
    • { ... } expression / Monitoring query performance

R

  • -reject_if object / Nested attributes
  • -relation option / Common options for all relations
  • -restrict value / :dependent
  • reduce function / MapReduce and the aggregation framework
  • Relation-specific options
    • $as option / Relation-specific options
    • $autosave option / Relation-specific options
    • $autobuild option / Relation-specific options
    • $primary_key option / Relation-specific options
    • $touch option / Relation-specific options
    • $dependent option / Relation-specific options
    • $foreign_key option / Relation-specific options
    • $order option / Relation-specific options
    • $counter_cache option / Relation-specific options
    • $index option / Relation-specific options
    • $validate option / Relation-specific options
    • $polymorphic option / Relation-specific options
    • $cyclic option / Relation-specific options
    • $cascaded_callbacks option / Relation-specific options
    • $store_as option / Relation-specific options
    • $versioned option / Relation-specific options
  • relations
    • name / Configuring relationships
    • options / Configuring relationships, Common options for all relations
    • block / Configuring relationships
    • $class_name option / Common options for all relations, :class_name
    • $inverse_of option / Common options for all relations, :inverse_of
    • $extend option / Common options for all relations
    • $inverse_class_name option / Common options for all relations
    • $name option / Common options for all relations
    • $relation option / Common options for all relations
  • reslen expression / Monitoring query performance
  • resource_id field / :as
  • resource_type field / :as
  • Ruby version
    • about / Ruby version

S

  • $skip / Choosing between MapReduce and the aggregation framework
  • $sort / The aggregation framework, Choosing between MapReduce and the aggregation framework
  • $sum / The aggregation framework
  • -store_as option / Relation-specific options, :store_as
  • save! function / Updating documents and attributes
  • serialization
    • about / Serialization with Mongoize
  • serialize method / Serialization with Mongoize
  • Sodibee
    • about / A practical approach using the Sodibee library system
    • functions / A practical approach using the Sodibee library system
    • prerequisites / Checking prerequisites
    • setting up / Setting up Sodibee
  • Sodibee, prerequisites
    • Ruby version / Ruby version
    • MongoDB version / MongoDB version
  • Sodibee, setting up
    • models, creating / Creating models
    • models, testing / Testing the models
  • sodibee_development.authors expression / Monitoring query performance
  • strong_parameters / Mass assignment and security
  • Symbol class
    • overloading / Overloading the Symbol class

T

  • -touch option / Relation-specific options, :touch
  • text index
    • about / Text index
  • time attributes
    • about / Date and time attributes
  • timestamping
    • about / Timestamping

U

  • $unwind / The aggregation framework, Choosing between MapReduce and the aggregation framework
  • upsert action / Updating documents and attributes

V

  • -validate option / Relation-specific options
    • about / :validate
  • -versioned option / Relation-specific options
  • validates_associated method / :validate
  • validation
    • URL / Validations
  • validations
    • about / Validations
  • Vehicle model
    • designing / Polymorphic relations
  • versioning
    • about / Versioning

W

  • -within_box / Query selectors
  • -within_circle / Query selectors
  • -within_polygon / Query selectors
  • -within_spherical_circle / Query selectors