making APIs easier. • Render responses as text, JSON, or XML • Geospatial indexing for location based queries. • Location-centric websites and mobile applications.
application • Versioning needed • Originally using GridFS • Travel720 - Gift registry web site • Self contained relations can take advantage of embedding documents
• Compatibility with other projects/gems • Similar API to ActiveRecord • Uses ActiveValidation • Mongoid Extras: Caching, Paranoid Documents, Versioning, Timestamping, Composite Keys
Rails based on Warden. Supports Mongoid out of box. • Carrierwave - simple and flexible way to upload files from Ruby Applications. Supports grid_fs. • Geocoder - complete geocoding solution for Rails. Adds geocoding by street or IP address, reverse geocoding, and distance queries. • Mongoid-rspec - RSpec matchers and macros for Mongoid.
the console as with ActiveRecord. • rails generate model Team name:string city:string location:array • No migrations needed! • Take advantage of embedded documents in models where applicable for increased performance. • Store large files using GridFS
or referenced • NO JOINS! • Objects that are referenced involve a separate query • Embedded documents can be very efficient with reducing queries to one while managing the size of the document • One to One, One to Many, and Many to Many relations available
inside other documents in the database. class Blog include Mongoid::Document embeds_many :posts end class Post include Mongoid::Document embedded_in :blog end
end class Document include Mongoid::Document embeds_many :comments, as: :commentable end class Comment include Mongoid::Document embedded_in :commentable, polymorphic: true end
:posts, dependent: :delete end class Post include Mongoid::Document belongs_to :blog end Referenced Relations - stores reference to a document in another collection, typically an id
chainable and lazily evaluated wrapper to a MongoDB dynamic query. • Chainable queries include: all_in all_of also_in and any_of asc desc distinct excludes includes limit near not_in only order_by skip where without
too loud to fall asleep to.", "created_at" : ISODate("2011-10-17T03:58:53Z"), "title" : "Impossible to sleep to - this guy.", "updated_at" : ISODate("2011-10-17T03:58:53Z"), "version" : 3, "versions" : [ {"title" : "Who is asleep?", "content" : "Wake up the guy next to you if they are asleep. Thanks.", "version" : 1, "created_at" : ISODate("2011-10-17T03:58:53Z")}, {"title" : "Who is asleep?", "content" : "Impossible. I am too loud to fall asleep to.", "created_at" : ISODate("2011-10-17T03:58:53Z"), "version" : 2 } ] }
RSpec does not refresh the database with each test run. • Database Cleaner to the rescue. It be setup to truncate a database before running tests. Add below after installing the DatabaseCleaner Gem. config.before(:suite) do DatabaseCleaner.strategy = :truncation DatabaseCleaner.orm = "mongoid" end