BSON). API is JS. Querying • Dynamic querying using expressions or JS • Server-side queries and MapReduce • Upserts and in-place updates including incr / decr, data structure operations, and embedded docs Master-slave replication, replica sets, auto-sharding GridFS for binary storage 2
: upsert a doc db.collection.update(criteria, obj, upsert, multi) • Single document replacement and upsert • In-place updates (one or more documents) 4
:age, Integer many :hobbies end class Hobby include MongoMapper::EmbeddedDocument key :name, String key :started, Time end $ gem install mongo_mapper user = User.new(:name => 'Brandon') user.hobbies.build(:name => 'Programming', :started => 10.years.ago) user.save! User.where(:name => 'Brandon').first
class Person include Mongoid::Document field :first_name, type: String field :middle_name, type: String field :last_name, type: String end Person.create!(first_name: "Heinrich", last_name: "Heine") Person.where(first_name: "Emmanuel").asc(:first_name).skip(20).limit(10) Person.all(conditions: { title: "Sir" }, limit: 5, sort: [[ :first_name, :asc ]])
like the console MongoMapper • Built on plugins • Better relational support Mongoid • Saves only changed properties using update() • Supports Master / slave replication • DSL for dynamic querying. Feels like the console. • Better docs, more active community • Seems to have gained real momentum Both look pretty great (I’ve been using Mongoid) 11