Learning Mongoid

Learning Mongoid
eBook: $17.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 20%!
Print + free eBook + free PacktLib access to the book: $47.98    Print cover: $29.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • A step-by-step guide that explains how to use Mongoid through lots of examples and code
  • Monitor and fine-tune the performance of your application
  • Work with the MongoDB aggregation framework

Book Details

Language : English
Paperback : 140 pages [ 235mm x 191mm ]
Release Date : December 2013
ISBN : 1782167501
ISBN 13 : 9781782167501
Author(s) : Gautam Rege
Topics and Technologies : All Books, Web Development, Open Source

Table of Contents

Chapter 1: What's so Awesome about Mongoid?
Chapter 2: Mongoid Document Model
Chapter 3: Persisting Documents
Chapter 4: Mongoid Relations
Chapter 5: Mongoid Queries
Chapter 6: Performance Tuning
Chapter 7: Mongoid Modules
  • Chapter 1: What's so Awesome about Mongoid?
    • A practical approach using the Sodibee library system
      • Checking prerequisites
        • Ruby version
        • MongoDB version
      • Setting up Sodibee
        • Creating models
        • Testing the models
      • Introducing Moped
        • Dynamic attributes
      • Introducing Origin
    • Notice about Mongoid 2.x
    • Mongoid and MongoMapper
    • Summary
  • Chapter 2: Mongoid Document Model
    • The Mongoid document
      • Basic attributes
      • Arrays and hashes
      • Date and time attributes
      • Serialization with Mongoize
      • Field aliases
    • Embedded documents
    • Localization
    • Mass assignment and security
    • Summary
  • Chapter 3: Persisting Documents
    • MongoDB persistence strategy
      • Binary JSON (BSON)
      • Memory maps, delayed sync, and journals
      • Creating documents
      • Updating documents and attributes
        • Database locks and transactions
        • Applications and lock versioning
        • The MongoDB findAndModify method
      • Atomic attribute updates
      • Dynamic attributes
      • Nested attributes
    • Validations
    • Callbacks
    • Summary
  • Chapter 4: Mongoid Relations
    • Configuring relationships
      • Common options for all relations
        • :class_name
        • :inverse_of
      • Relation-specific options
    • has_one – the one-to-one relation
      • :as
      • :autosave
      • :autobuild
      • :dependent
      • :primary_key
      • :foreign_key
      • :validate
    • has_many – the many-to-one relation
      • :order
      • :before_add, :after_add, :before_remove, and :after_remove
    • The belongs_to relation
      • :index
      • :polymorphic
      • :touch
      • :counter_cache
    • has_and_belongs_to_many – the many-to-many relation
      • :inverse_of
    • Polymorphic relations
    • embeds_many – embedding many documents
      • :cascade_callbacks
      • :store_as
      • :cyclic
    • embeds_one – embed one document
    • embedded_in – resolving children
    • Embedded polymorphic relations
    • Summary
  • Chapter 5: Mongoid Queries
    • Origins of Origin
    • Query selectors
      • Overloading the Symbol class
    • Mongoid criteria
    • Queries on arrays and hashes
      • Scopes
    • Atomic modifiers
      • find_and_modify
    • Querying with indexed fields
      • Covered queries
    • The aggregation framework
    • Geolocation queries
    • Summary
  • Chapter 6: Performance Tuning
    • MongoDB environment
    • Indexes
      • Write concern
      • Compound index
      • Multikey index
      • Hashed index
      • Text index
    • IdentityMap
      • n+1 query problem and eager loading
    • MapReduce and the aggregation framework
      • Using the aggregation framework
      • Choosing between MapReduce and the aggregation framework
    • Monitoring query performance
      • Profiling MongoDB
      • Statistical data
      • Hint and currentOp
    • Good practices and recommendations
    • Summary
  • Chapter 7: Mongoid Modules
    • Timestamping
    • Versioning
    • Paranoia
    • Acts as state machine (aasm)
      • carrierwave
      • mongoid-audit
      • devise
    • Summary

Gautam Rege

Gautam Rege has been working in Ruby since 2007 and has been experimenting a lot with MongoDB. He believes Ruby is indeed the language of the next generation – very human-readable, flexible and extremely enjoyable. MongoDB is the new age NoSQL forerunner. It has rightly started to gain ‘humongous’ patronage. Gautam works a lot in Rails and at Josh Software Private Limited, the company he co-founded, working exclusively in Ruby and Ruby-related technologies. He is well versed with Rhodes (the Ruby mobile framework), Merb, Sinatra and occasionally also experiments with JS frameworks like Sproutcore, and Backbone.js

Code Downloads

Download the code and support files for this book.

Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Learning Mongoid +    Data Visualization with D3.js Cookbook =
50% Off
the second eBook
Price for both: $31.95

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Learn the syntax of Mongoid 4 with Rails 4
  • Understand moped, the new Ruby driver for MongoDB Learn about document relations in Mongoid
  • Understand origin, the new querying DSL
  • Manage indexes in Mongoid
  • Learn about gems that work with Mongoid
  • Tune and monitor performance

In Detail

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.


A step-by-step tutorial with focused examples that will help you build scalable, high performance Rails web applications with Mongoid.

Who this book is for

If you are an application developer who wants to learn how to use Mongoid in a Rails application, this book will be great for you. You are expected to be familiar with MongoDB and Ruby.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software