SlideShare a Scribd company logo
1 of 104
Download to read offline
4 real

                railswaycon 2010, berlin.

                jan krutisch <jan.krutisch@mindmatters.de>
                http://jan.krutisch.de/



Montag, 31. Mai 2010
http://www.cashbits.de/




Montag, 31. Mai 2010
mongodb you say?




Montag, 31. Mai 2010
document database




Montag, 31. Mai 2010
NoS
                                       QL
                                inclu
                                      ded!



                document database




Montag, 31. Mai 2010
no fixed schema
                no migrations



Montag, 31. Mai 2010
rich data structure




Montag, 31. Mai 2010
id   title   descr   pos_lat pos_lng




Montag, 31. Mai 2010
{
                       "_id" : ObjectId("4c00245062610475a005afcd"),
                       "address" : "Bernstorffstr. 174n22767 HamburgnDE",
                       "description" : null,
                       "position" : {
                         "lat" : 53.5600912,
                         "lng" : 9.9596977
                       },
                       "tags" : [
                         "hausarzt",
                         "naturheilverfahren",
                         "akupunktur",
                         "allgemeinmedizin"
                       ],
                       "title" : "Dr. med. Lilo Eisenbarth",
                       "loxicon_id" : 808261
                }




Montag, 31. Mai 2010
Montag, 31. Mai 2010
Montag, 31. Mai 2010
                       ✗
Montag, 31. Mai 2010
BSON

                ‣ Binary serialized JSON
                ‣ http://bsonspec.org/
                ‣ Goals: Lightweight, Traversable, Efficient
                ‣ Format for Datastorage and Wire




Montag, 31. Mai 2010
rich queries




Montag, 31. Mai 2010
Queries
                ‣ expressed BSON query documents
                ‣ very flexible
                ‣ relatively simple query expressions
                ‣ pretty close to SQL conceptually
                ‣ examples will follow
                ‣ on top: map/reduce for aggregation


Montag, 31. Mai 2010
Scaling

                ‣ Master > Slave replication
                ‣ Replica Pairs (with Arbiter)
                ‣ Replica Sets (Target: 1.6)
                ‣ Autosharding (Target: 1.6)




Montag, 31. Mai 2010
A few words on durability

                ‣ MongoDB only fsyncs every <n> seconds
                ‣ There‘s a desaster waiting to happen!
                ‣ When in production, replicate!
                ‣ This is not as bad as it sounds.




Montag, 31. Mai 2010
Installation/Hosting




Montag, 31. Mai 2010
OS X:
                $ brew install mongodb



Montag, 31. Mai 2010
Ubuntu/Debian:
                theres an apt for that



Montag, 31. Mai 2010
excu
                                        se
                                  the p
                Ubuntu/Debian:         un


                theres an apt for that



Montag, 31. Mai 2010
http://www.mongodb.org/display/DOCS/Downloads
Montag, 31. Mai 2010
http://www.mongodb.org/display/DOCS/Downloads
Montag, 31. Mai 2010
also




Montag, 31. Mai 2010
http://mongohq.com/
Montag, 31. Mai 2010
http://mongomachine.com/
Montag, 31. Mai 2010
basic usage




Montag, 31. Mai 2010
$ mongo




Montag, 31. Mai 2010
> use test
                switched to db test

                db.quotes.save({
                  text: "You can observe a lot just by watching.",
                  from: "Yogi Berra", created_at: new Date()
                });

                db.quotes.save({
                  text: "Silence is one of the hardest arguments to refute.",
                  from: "Josh Billings", created_at: new Date()
                });




Montag, 31. Mai 2010
let‘s query




Montag, 31. Mai 2010
db.quotes.find();
                // returns all records in collection.

                db.quotes.find({from: "Yogi Berra"});
                {
                  "_id" : ObjectId("4c0022551496fc2051e93695"),
                  "text" : "You can observe a lot just by watching.",
                  "from" : "Yogi Berra",
                  "created_at" : "Fri May 28 2010 22:06:45 GMT+0200 (CEST)"
                }




Montag, 31. Mai 2010
$lt    <
                $gt    >
                $lte   <=
                $gte   >=
                $ne    !=

Montag, 31. Mai 2010
db.quotes.find({from: {"$ne": "Yogi Berra"}});
                {
                  "_id" : ObjectId("4c0022551496fc2051e93696"),
                  "text" : "Silence is one of the hardest arguments to refute.",
                  "from" : "Josh Billings",
                  "created_at" : "Fri May 28 2010 22:06:45 GMT+0200 (CEST)"
                }




Montag, 31. Mai 2010
$in    IN (2,3,4)
                $nin   NOT IN
                $all   [2,3] ~ [1,2,3]


Montag, 31. Mai 2010
db.quotes.find({from:{ "$in":["Yogi Berra","Josh Billings"]}});
                { "_id" : ObjectId("4c0022551496fc2051e93695"), "text" : "You can..."...}
                { "_id" : ObjectId("4c0022551496fc2051e93696"), "text" : "Silence..."...}

                db.arrays.save({list: [1,2,3]});
                db.arrays.save({list: [4,5,6]});
                db.arrays.save({list: [3,4,5]});

                db.arrays.find({list:{ "$in":[3,4]}});
                { "_id" : ObjectId("4c0025461496fc2051e93697"), "list" : [ 1, 2, 3 ] }
                { "_id" : ObjectId("4c0025501496fc2051e93698"), "list" : [ 4, 5, 6 ] }
                { "_id" : ObjectId("4c0025591496fc2051e93699"), "list" : [ 3, 4, 5 ] }

                db.arrays.find({list:{ "$all":[3,5]}});
                { "_id" : ObjectId("4c0025591496fc2051e93699"), "list" : [ 3, 4, 5 ] }




Montag, 31. Mai 2010
$mod      yah, RLY
                $size     okay
                $exists   NOT NULL
                $type     huh?


Montag, 31. Mai 2010
db.arrays.find({list:{ "$mod":[4,0]}});
                { "_id" : ObjectId("4c0025501496fc2051e93698"), "list" : [ 4, 5, 6 ] }
                { "_id" : ObjectId("4c0025591496fc2051e93699"), "list" : [ 3, 4, 5 ] }

                db.arrays.find({list:{ "$size":3}});
                { "_id" : ObjectId("4c0025461496fc2051e93697"), "list" : [ 1, 2, 3 ] }
                { "_id" : ObjectId("4c0025501496fc2051e93698"), "list" : [ 4, 5, 6 ] }
                { "_id" : ObjectId("4c0025591496fc2051e93699"), "list" : [ 3, 4, 5 ] }

                db.arrays.find({list: {"$exists": true}});
                [...]

                db.arrays.find({list: {"$type": 1}});
                [...]




Montag, 31. Mai 2010
...and...




Montag, 31. Mai 2010
db.quotes.find({from: /^Yog/});
                [...]

                db.quotes.find({from: /^Yog/});
                [...]

                db.quotes.find("this.from == 'Yogi Berra'");
                [...]

                db.quotes.find({"$where": "this.from == 'Yogi Berra'"});
                [...]




Montag, 31. Mai 2010
sort()




Montag, 31. Mai 2010
db.quotes.find().sort({from:1})
                {"from" : "Josh Billings" ... }
                {"from" : "Yogi Berra"     ...}

                db.quotes.find().sort({from:-1})
                {"from" : "Yogi Berra"     ...}
                {"from" : "Josh Billings" ... }




Montag, 31. Mai 2010
limit()




Montag, 31. Mai 2010
skip() // == OFFSET




Montag, 31. Mai 2010
count()




Montag, 31. Mai 2010
db.quotes.find().count();
                2




Montag, 31. Mai 2010
Indices




Montag, 31. Mai 2010
Indexing

                ‣ Same concept as SQL-Indices
                ‣ You want them. (Same concept as with...)
                ‣ Sort order, unique, compound, geospatial




Montag, 31. Mai 2010
db.quotes.ensureIndex({from: 1});

                db.quotes.ensureIndex({from: -1});

                db.quotes.ensureIndex({text: 1}, {unique: true});

                db.quotes.ensureIndex({from: 1, text: 1});

                db.quotes.dropIndexes();

                db.quotes.dropIndex({from: 1, text: 1});

                db.quotes.reIndex();




Montag, 31. Mai 2010
map/reduce,
                we can haz it, too



Montag, 31. Mai 2010
function() {
                         this.tags.forEach(function(z) {
                           emit(z, {count: 1});
                         });
                       }



                       function(key, values) {
                         var total = 0;
                         values.forEach(function(v) { total += v });
                         return {count: total}
                       }




Montag, 31. Mai 2010
(it‘s not fast...)




Montag, 31. Mai 2010
one more thing




Montag, 31. Mai 2010
GridFS




Montag, 31. Mai 2010
GridFS file storage

                ‣ Binary fields in BSON limited to 4MB
                ‣ GridFS API fixes that, files stored as chunks
                ‣ Use the language drivers




Montag, 31. Mai 2010
I‘m in u‘r rubies,
                querying teh MongoDB!



Montag, 31. Mai 2010
ruby integration
                ‣ mongo gem
                ‣ bson/ bson_ext gem

                ‣ mongo_mapper
                ‣ mongoid



Montag, 31. Mai 2010
Basic driver usage




Montag, 31. Mai 2010
require 'rubygems'
                require 'mongo'

                db = Mongo::Connection.new.db("test")
                doc = {
                  :text => "You can observe a lot just by watching.",
                  :from => "Yogi Berra",
                  :created_at => Time.now
                }
                db['quotes'].insert(doc)
                db['quotes'].find.each do |row|
                  puts row.inspect
                end

                {
                       "_id"=>$oid4bffe2896261046e79000001,
                       "from"=>"Yogi Berra",
                       "created_at"=>Fri May 28 15:34:33 UTC 2010,
                       "text"=>"You can observe a lot just by watching."
                }




Montag, 31. Mai 2010
require 'rubygems'
                require 'mongo'

                db = Mongo::Connection.new.db("test")

                100.times do |i|
                  db['numbers'].insert({"i" => i})
                end

                db['numbers'].find("i" => {"$lt" => 2}).each do |row|
                  puts row.inspect
                end

                # {"_id"=>$oid4bffe4396261046f25000001, "i"=>0}
                # {"_id"=>$oid4bffe4396261046f25000002, "i"=>1}




Montag, 31. Mai 2010
db['text_entries'].drop_index("tags_1")
                db['text_entries'].create_index("tags")
                db['text_entries'].index_information




Montag, 31. Mai 2010
GridFS usage




Montag, 31. Mai 2010
db = Mongo::Connection.new.db("test")

                grid = Mongo::Grid.new(db)

                id = grid.put("You can put Strings in here",
                  :filename => 'test.txt')

                file = grid.get(id)
                puts file.filename
                puts file.read

                grid.delete(id)

                grid.put(
                  File.open("/Users/jankrutisch/Dropbox/Photos/IMGP8989.jpg")
                )




Montag, 31. Mai 2010
fs = Mongo::GridFileSystem.new(db)

                fs.open("test.txt", "w") do |f|
                  f.write "You can put stuff in here"
                end

                fs.open("test.txt", "r") do |f|
                  puts f.read
                end

                fs.delete("test.txt")




Montag, 31. Mai 2010
ODMs




Montag, 31. Mai 2010
mongo_mapper
                ‣ By John Nunemaker (@jnunemaker)
                ‣ works
                ‣ a few quirks
                ‣ almost completely undocumented
                ‣ Some stuff is still missing



Montag, 31. Mai 2010
Montag, 31. Mai 2010
# config/initializers/mongo_mapper.rb
                File.open(File.join(Rails.root, 'config/mongodb.yml'), 'r') do |f|
                  @settings = YAML.load(f)[Rails.env]
                end
                MongoMapper.connection = Mongo::Connection.from_uri(@settings["connection"]) if @settings["connection"]

                MongoMapper.database = @settings["database"]




Montag, 31. Mai 2010
class Loop
                  include MongoMapper::Document
                  key :name
                  key :public, Boolean
                  key :message_id
                  key :plays_and_downloads, Integer

                  belongs_to :user
                  timestamps!
                end




Montag, 31. Mai 2010
@loops = Loop.all(
                ! :user_id => {"$exists" => true},
                ! :order => 'created_at DESC',
                ! :limit => 10
                )




Montag, 31. Mai 2010
„created_at DESC“ ?!?




Montag, 31. Mai 2010
mongoid




Montag, 31. Mai 2010
mongoid
                ‣ By Durran Jordan (Hashrocket)
                ‣ Two major versions:
                       ‣ 1.x (currently 1.9) for Rails 2.3 compatibility
                       ‣ 2.x (currently 2.x beta) for Rails 3 compatibility
                ‣ Good documentation
                ‣ API is better (?)



Montag, 31. Mai 2010
File.open(File.join(RAILS_ROOT, 'config/mongodb.yml'), 'r') do |f|
                  @settings = YAML.load(f)[RAILS_ENV]
                end

                Mongoid::Config.instance.from_hash(@settings)




Montag, 31. Mai 2010
class Loop
                  include Mongoid::Document
                  include Mongoid::Timestamps

                       field   :name
                       field   :public, :type => Boolean
                       field   :message_id
                       field   :plays_and_downloads, :type => Integer

                  belongs_to_related :user
                end




Montag, 31. Mai 2010
Criteria API

                ‣ A bit like Arel
                ‣ chainable method calls
                ‣ Named scopes




Montag, 31. Mai 2010
Embedded Documents




Montag, 31. Mai 2010
class Person
                  include Mongoid::Document
                  field :first_name
                  field :last_name
                  embeds_one :address
                  embeds_many :phones
                end

                class Address
                  include Mongoid::Document
                  field :street
                  field :city
                  field :state
                  field :post_code
                  embedded_in :person, :inverse_of => :address
                end




Montag, 31. Mai 2010
GridFS




Montag, 31. Mai 2010
acts_as_attachment




Montag, 31. Mai 2010
class Loop
                  include Mongoid::Document
                  include Mongoid::Timestamps

                   include Mongoid::Grid
                   field   :name
                   field   :public, :type => Boolean
                   field   :message_id
                   field   :plays_and_downloads, :type => Integer


                   attachment :nan
                end




Montag, 31. Mai 2010
using MongoDB 4 real




Montag, 31. Mai 2010
Installation is easy




Montag, 31. Mai 2010
(if you‘re using Ubuntu)




Montag, 31. Mai 2010
setting up replication




Montag, 31. Mai 2010
$ mongod --master
                or
                master = true # mongodb.conf




                $ mongod --slave --source
                slaveserver.example.com

                slave = true
                source = slaveserver.example.com




Montag, 31. Mai 2010
OpLog size!




Montag, 31. Mai 2010
„security“




Montag, 31. Mai 2010
memory usage?




Montag, 31. Mai 2010
limits?




Montag, 31. Mai 2010
stability?




Montag, 31. Mai 2010
bonus level




Montag, 31. Mai 2010
you‘ve made it this far!




Montag, 31. Mai 2010
MongoDB explain()ed




Montag, 31. Mai 2010
db.text_entries.find({tags: "restaurant"}).limit(10).explain();
                {
                ! "cursor" : "BtreeCursor tags_1",
                ! "indexBounds" : [
                ! ! [
                ! ! ! {
                ! ! ! ! "tags" : "restaurant"
                ! ! ! },
                ! ! ! {
                ! ! ! ! "tags" : "restaurant"
                ! ! ! }
                ! ! ]
                ! ],
                ! "nscanned" : 210,
                ! "nscannedObjects" : 210,
                ! "n" : 10,
                ! "millis" : 0,
                ! [...]
                }




Montag, 31. Mai 2010
My personal impression




Montag, 31. Mai 2010
Extremely easy to grasp




Montag, 31. Mai 2010
Normalisation suXXorZ




Montag, 31. Mai 2010
Migrations hurt




Montag, 31. Mai 2010
Seems to be very fast




Montag, 31. Mai 2010
Some issues for small
                projects



Montag, 31. Mai 2010
I




Montag, 31. Mai 2010
thanks for listening.




Montag, 31. Mai 2010
Moi
                ‣ jan.krutisch@mindmatters.de
                ‣ http://jan.krutisch.de/
                ‣ http://github.com/halfbyte/
                ‣ http://twitter.com/halfbyte
                ‣ http://www.mindmatters.de/



Montag, 31. Mai 2010
Pointers

                ‣ http://www.mongodb.org/
                ‣ http://www.mongoid.org/
                ‣ http://github.com/jnunemaker/mongo_mapper




Montag, 31. Mai 2010

More Related Content

What's hot

Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
Building Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDBBuilding Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDBGreat Wide Open
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDBNate Abele
 
Proved PHP Design Patterns for Data Persistence
Proved PHP Design Patterns for Data PersistenceProved PHP Design Patterns for Data Persistence
Proved PHP Design Patterns for Data PersistenceGjero Krsteski
 
Basic crud operation
Basic crud operationBasic crud operation
Basic crud operationzarigatongy
 
Persisting dynamic data with mongodb and mongomapper
Persisting dynamic data with mongodb and mongomapperPersisting dynamic data with mongodb and mongomapper
Persisting dynamic data with mongodb and mongomapperwonko
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDBTakahiro Inoue
 
ぐだ生 Java入門第三回(文字コードの話)(Keynote版)
ぐだ生 Java入門第三回(文字コードの話)(Keynote版)ぐだ生 Java入門第三回(文字コードの話)(Keynote版)
ぐだ生 Java入門第三回(文字コードの話)(Keynote版)Makoto Yamazaki
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaScott Hernandez
 
MongoDB @ Frankfurt NoSql User Group
MongoDB @  Frankfurt NoSql User GroupMongoDB @  Frankfurt NoSql User Group
MongoDB @ Frankfurt NoSql User GroupChris Harris
 
Building a Social Network with MongoDB
  Building a Social Network with MongoDB  Building a Social Network with MongoDB
Building a Social Network with MongoDBFred Chu
 
Windows ストアーアプリで SQLite を使ってみよう
Windows ストアーアプリで SQLite を使ってみようWindows ストアーアプリで SQLite を使ってみよう
Windows ストアーアプリで SQLite を使ってみようShinichiAoyagi
 
c++ boost and STL
c++  boost and STLc++  boost and STL
c++ boost and STLCOMAQA.BY
 
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例Naoki Sega
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationMongoDB
 
Json improvements in my sql 8.0
Json improvements in my sql 8.0  Json improvements in my sql 8.0
Json improvements in my sql 8.0 Mysql User Camp
 
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제홍준 김
 

What's hot (20)

Jongo mongo sv
Jongo mongo svJongo mongo sv
Jongo mongo sv
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Building Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDBBuilding Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDB
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
Proved PHP Design Patterns for Data Persistence
Proved PHP Design Patterns for Data PersistenceProved PHP Design Patterns for Data Persistence
Proved PHP Design Patterns for Data Persistence
 
Basic crud operation
Basic crud operationBasic crud operation
Basic crud operation
 
Persisting dynamic data with mongodb and mongomapper
Persisting dynamic data with mongodb and mongomapperPersisting dynamic data with mongodb and mongomapper
Persisting dynamic data with mongodb and mongomapper
 
Indexing
IndexingIndexing
Indexing
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDB
 
ぐだ生 Java入門第三回(文字コードの話)(Keynote版)
ぐだ生 Java入門第三回(文字コードの話)(Keynote版)ぐだ生 Java入門第三回(文字コードの話)(Keynote版)
ぐだ生 Java入門第三回(文字コードの話)(Keynote版)
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with Morphia
 
MongoDB @ Frankfurt NoSql User Group
MongoDB @  Frankfurt NoSql User GroupMongoDB @  Frankfurt NoSql User Group
MongoDB @ Frankfurt NoSql User Group
 
Building a Social Network with MongoDB
  Building a Social Network with MongoDB  Building a Social Network with MongoDB
Building a Social Network with MongoDB
 
Windows ストアーアプリで SQLite を使ってみよう
Windows ストアーアプリで SQLite を使ってみようWindows ストアーアプリで SQLite を使ってみよう
Windows ストアーアプリで SQLite を使ってみよう
 
Swift & JSON
Swift & JSONSwift & JSON
Swift & JSON
 
c++ boost and STL
c++  boost and STLc++  boost and STL
c++ boost and STL
 
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
 
Json improvements in my sql 8.0
Json improvements in my sql 8.0  Json improvements in my sql 8.0
Json improvements in my sql 8.0
 
Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제Mongo db문서의생성,갱신,삭제
Mongo db문서의생성,갱신,삭제
 

Similar to MongoDB & Mongomapper 4 real

Tree tricks osdc_melbourne_20101124
Tree tricks osdc_melbourne_20101124Tree tricks osdc_melbourne_20101124
Tree tricks osdc_melbourne_20101124David Fetter
 
Cassandra devoxx 2010
Cassandra devoxx 2010Cassandra devoxx 2010
Cassandra devoxx 2010jbellis
 
12 Hours To Rate A Rails Application
12 Hours To Rate A Rails Application12 Hours To Rate A Rails Application
12 Hours To Rate A Rails Applicationehuard
 
Document-Oriented Databases: Couchdb Primer
Document-Oriented Databases: Couchdb PrimerDocument-Oriented Databases: Couchdb Primer
Document-Oriented Databases: Couchdb Primerjsiarto
 
Mongo db readingdocumentusecases
Mongo db readingdocumentusecasesMongo db readingdocumentusecases
Mongo db readingdocumentusecaseszarigatongy
 

Similar to MongoDB & Mongomapper 4 real (7)

Mongo db
Mongo dbMongo db
Mongo db
 
Tree tricks osdc_melbourne_20101124
Tree tricks osdc_melbourne_20101124Tree tricks osdc_melbourne_20101124
Tree tricks osdc_melbourne_20101124
 
Cassandra devoxx 2010
Cassandra devoxx 2010Cassandra devoxx 2010
Cassandra devoxx 2010
 
12 Hours To Rate A Rails Application
12 Hours To Rate A Rails Application12 Hours To Rate A Rails Application
12 Hours To Rate A Rails Application
 
Document-Oriented Databases: Couchdb Primer
Document-Oriented Databases: Couchdb PrimerDocument-Oriented Databases: Couchdb Primer
Document-Oriented Databases: Couchdb Primer
 
Mongo db readingdocumentusecases
Mongo db readingdocumentusecasesMongo db readingdocumentusecases
Mongo db readingdocumentusecases
 
12 adv-manip
12 adv-manip12 adv-manip
12 adv-manip
 

More from jan_mindmatters

Ruby for Artists and Tinkerers. A non-presentation.
Ruby for Artists and Tinkerers. A non-presentation.Ruby for Artists and Tinkerers. A non-presentation.
Ruby for Artists and Tinkerers. A non-presentation.jan_mindmatters
 
realtime audio on ze web @ hhjs
realtime audio on ze web @ hhjsrealtime audio on ze web @ hhjs
realtime audio on ze web @ hhjsjan_mindmatters
 
Railsrumble railscamphh 2010
Railsrumble railscamphh 2010Railsrumble railscamphh 2010
Railsrumble railscamphh 2010jan_mindmatters
 
MongoDB on Rails (and Ruby)
MongoDB on Rails (and Ruby)MongoDB on Rails (and Ruby)
MongoDB on Rails (and Ruby)jan_mindmatters
 
10 fun projects to improve your coding skills
10 fun projects to improve your coding skills10 fun projects to improve your coding skills
10 fun projects to improve your coding skillsjan_mindmatters
 
Open Source Hardware - Of makers and tinkerers
Open Source Hardware - Of makers and tinkerersOpen Source Hardware - Of makers and tinkerers
Open Source Hardware - Of makers and tinkerersjan_mindmatters
 
Liebe Dein Frontend wie Dich selbst! HAML & SASS & COMPASS & less
Liebe Dein Frontend wie Dich selbst! HAML & SASS & COMPASS & lessLiebe Dein Frontend wie Dich selbst! HAML & SASS & COMPASS & less
Liebe Dein Frontend wie Dich selbst! HAML & SASS & COMPASS & lessjan_mindmatters
 
Facebook mit Rails und Facebooker
Facebook mit Rails und FacebookerFacebook mit Rails und Facebooker
Facebook mit Rails und Facebookerjan_mindmatters
 
Show the frontend some love - HAML, SASS and COMPASS
Show the frontend some love - HAML, SASS and COMPASSShow the frontend some love - HAML, SASS and COMPASS
Show the frontend some love - HAML, SASS and COMPASSjan_mindmatters
 
Lehmanns Rails Erweitern
Lehmanns Rails ErweiternLehmanns Rails Erweitern
Lehmanns Rails Erweiternjan_mindmatters
 
Rails i18n - Railskonferenz 2007
Rails i18n - Railskonferenz 2007Rails i18n - Railskonferenz 2007
Rails i18n - Railskonferenz 2007jan_mindmatters
 

More from jan_mindmatters (13)

Ruby for Artists and Tinkerers. A non-presentation.
Ruby for Artists and Tinkerers. A non-presentation.Ruby for Artists and Tinkerers. A non-presentation.
Ruby for Artists and Tinkerers. A non-presentation.
 
realtime audio on ze web @ hhjs
realtime audio on ze web @ hhjsrealtime audio on ze web @ hhjs
realtime audio on ze web @ hhjs
 
Railsrumble railscamphh 2010
Railsrumble railscamphh 2010Railsrumble railscamphh 2010
Railsrumble railscamphh 2010
 
MongoDB on Rails (and Ruby)
MongoDB on Rails (and Ruby)MongoDB on Rails (and Ruby)
MongoDB on Rails (and Ruby)
 
10 fun projects to improve your coding skills
10 fun projects to improve your coding skills10 fun projects to improve your coding skills
10 fun projects to improve your coding skills
 
Open Source Hardware - Of makers and tinkerers
Open Source Hardware - Of makers and tinkerersOpen Source Hardware - Of makers and tinkerers
Open Source Hardware - Of makers and tinkerers
 
Liebe Dein Frontend wie Dich selbst! HAML & SASS & COMPASS & less
Liebe Dein Frontend wie Dich selbst! HAML & SASS & COMPASS & lessLiebe Dein Frontend wie Dich selbst! HAML & SASS & COMPASS & less
Liebe Dein Frontend wie Dich selbst! HAML & SASS & COMPASS & less
 
Facebook mit Rails und Facebooker
Facebook mit Rails und FacebookerFacebook mit Rails und Facebooker
Facebook mit Rails und Facebooker
 
Show the frontend some love - HAML, SASS and COMPASS
Show the frontend some love - HAML, SASS and COMPASSShow the frontend some love - HAML, SASS and COMPASS
Show the frontend some love - HAML, SASS and COMPASS
 
HAML / SASS and COMPASS
HAML / SASS and COMPASSHAML / SASS and COMPASS
HAML / SASS and COMPASS
 
Merb. Rails in anders.
Merb. Rails in anders.Merb. Rails in anders.
Merb. Rails in anders.
 
Lehmanns Rails Erweitern
Lehmanns Rails ErweiternLehmanns Rails Erweitern
Lehmanns Rails Erweitern
 
Rails i18n - Railskonferenz 2007
Rails i18n - Railskonferenz 2007Rails i18n - Railskonferenz 2007
Rails i18n - Railskonferenz 2007
 

Recently uploaded

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Recently uploaded (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

MongoDB & Mongomapper 4 real

  • 1. 4 real railswaycon 2010, berlin. jan krutisch <jan.krutisch@mindmatters.de> http://jan.krutisch.de/ Montag, 31. Mai 2010
  • 5. NoS QL inclu ded! document database Montag, 31. Mai 2010
  • 6. no fixed schema no migrations Montag, 31. Mai 2010
  • 8. id title descr pos_lat pos_lng Montag, 31. Mai 2010
  • 9. { "_id" : ObjectId("4c00245062610475a005afcd"), "address" : "Bernstorffstr. 174n22767 HamburgnDE", "description" : null, "position" : { "lat" : 53.5600912, "lng" : 9.9596977 }, "tags" : [ "hausarzt", "naturheilverfahren", "akupunktur", "allgemeinmedizin" ], "title" : "Dr. med. Lilo Eisenbarth", "loxicon_id" : 808261 } Montag, 31. Mai 2010
  • 11. Montag, 31. Mai 2010 ✗
  • 13. BSON ‣ Binary serialized JSON ‣ http://bsonspec.org/ ‣ Goals: Lightweight, Traversable, Efficient ‣ Format for Datastorage and Wire Montag, 31. Mai 2010
  • 15. Queries ‣ expressed BSON query documents ‣ very flexible ‣ relatively simple query expressions ‣ pretty close to SQL conceptually ‣ examples will follow ‣ on top: map/reduce for aggregation Montag, 31. Mai 2010
  • 16. Scaling ‣ Master > Slave replication ‣ Replica Pairs (with Arbiter) ‣ Replica Sets (Target: 1.6) ‣ Autosharding (Target: 1.6) Montag, 31. Mai 2010
  • 17. A few words on durability ‣ MongoDB only fsyncs every <n> seconds ‣ There‘s a desaster waiting to happen! ‣ When in production, replicate! ‣ This is not as bad as it sounds. Montag, 31. Mai 2010
  • 19. OS X: $ brew install mongodb Montag, 31. Mai 2010
  • 20. Ubuntu/Debian: theres an apt for that Montag, 31. Mai 2010
  • 21. excu se the p Ubuntu/Debian: un theres an apt for that Montag, 31. Mai 2010
  • 29. > use test switched to db test db.quotes.save({ text: "You can observe a lot just by watching.", from: "Yogi Berra", created_at: new Date() }); db.quotes.save({ text: "Silence is one of the hardest arguments to refute.", from: "Josh Billings", created_at: new Date() }); Montag, 31. Mai 2010
  • 31. db.quotes.find(); // returns all records in collection. db.quotes.find({from: "Yogi Berra"}); { "_id" : ObjectId("4c0022551496fc2051e93695"), "text" : "You can observe a lot just by watching.", "from" : "Yogi Berra", "created_at" : "Fri May 28 2010 22:06:45 GMT+0200 (CEST)" } Montag, 31. Mai 2010
  • 32. $lt < $gt > $lte <= $gte >= $ne != Montag, 31. Mai 2010
  • 33. db.quotes.find({from: {"$ne": "Yogi Berra"}}); { "_id" : ObjectId("4c0022551496fc2051e93696"), "text" : "Silence is one of the hardest arguments to refute.", "from" : "Josh Billings", "created_at" : "Fri May 28 2010 22:06:45 GMT+0200 (CEST)" } Montag, 31. Mai 2010
  • 34. $in IN (2,3,4) $nin NOT IN $all [2,3] ~ [1,2,3] Montag, 31. Mai 2010
  • 35. db.quotes.find({from:{ "$in":["Yogi Berra","Josh Billings"]}}); { "_id" : ObjectId("4c0022551496fc2051e93695"), "text" : "You can..."...} { "_id" : ObjectId("4c0022551496fc2051e93696"), "text" : "Silence..."...} db.arrays.save({list: [1,2,3]}); db.arrays.save({list: [4,5,6]}); db.arrays.save({list: [3,4,5]}); db.arrays.find({list:{ "$in":[3,4]}}); { "_id" : ObjectId("4c0025461496fc2051e93697"), "list" : [ 1, 2, 3 ] } { "_id" : ObjectId("4c0025501496fc2051e93698"), "list" : [ 4, 5, 6 ] } { "_id" : ObjectId("4c0025591496fc2051e93699"), "list" : [ 3, 4, 5 ] } db.arrays.find({list:{ "$all":[3,5]}}); { "_id" : ObjectId("4c0025591496fc2051e93699"), "list" : [ 3, 4, 5 ] } Montag, 31. Mai 2010
  • 36. $mod yah, RLY $size okay $exists NOT NULL $type huh? Montag, 31. Mai 2010
  • 37. db.arrays.find({list:{ "$mod":[4,0]}}); { "_id" : ObjectId("4c0025501496fc2051e93698"), "list" : [ 4, 5, 6 ] } { "_id" : ObjectId("4c0025591496fc2051e93699"), "list" : [ 3, 4, 5 ] } db.arrays.find({list:{ "$size":3}}); { "_id" : ObjectId("4c0025461496fc2051e93697"), "list" : [ 1, 2, 3 ] } { "_id" : ObjectId("4c0025501496fc2051e93698"), "list" : [ 4, 5, 6 ] } { "_id" : ObjectId("4c0025591496fc2051e93699"), "list" : [ 3, 4, 5 ] } db.arrays.find({list: {"$exists": true}}); [...] db.arrays.find({list: {"$type": 1}}); [...] Montag, 31. Mai 2010
  • 39. db.quotes.find({from: /^Yog/}); [...] db.quotes.find({from: /^Yog/}); [...] db.quotes.find("this.from == 'Yogi Berra'"); [...] db.quotes.find({"$where": "this.from == 'Yogi Berra'"}); [...] Montag, 31. Mai 2010
  • 41. db.quotes.find().sort({from:1}) {"from" : "Josh Billings" ... } {"from" : "Yogi Berra" ...} db.quotes.find().sort({from:-1}) {"from" : "Yogi Berra" ...} {"from" : "Josh Billings" ... } Montag, 31. Mai 2010
  • 43. skip() // == OFFSET Montag, 31. Mai 2010
  • 45. db.quotes.find().count(); 2 Montag, 31. Mai 2010
  • 47. Indexing ‣ Same concept as SQL-Indices ‣ You want them. (Same concept as with...) ‣ Sort order, unique, compound, geospatial Montag, 31. Mai 2010
  • 48. db.quotes.ensureIndex({from: 1}); db.quotes.ensureIndex({from: -1}); db.quotes.ensureIndex({text: 1}, {unique: true}); db.quotes.ensureIndex({from: 1, text: 1}); db.quotes.dropIndexes(); db.quotes.dropIndex({from: 1, text: 1}); db.quotes.reIndex(); Montag, 31. Mai 2010
  • 49. map/reduce, we can haz it, too Montag, 31. Mai 2010
  • 50. function() { this.tags.forEach(function(z) { emit(z, {count: 1}); }); } function(key, values) { var total = 0; values.forEach(function(v) { total += v }); return {count: total} } Montag, 31. Mai 2010
  • 52. one more thing Montag, 31. Mai 2010
  • 54. GridFS file storage ‣ Binary fields in BSON limited to 4MB ‣ GridFS API fixes that, files stored as chunks ‣ Use the language drivers Montag, 31. Mai 2010
  • 55. I‘m in u‘r rubies, querying teh MongoDB! Montag, 31. Mai 2010
  • 56. ruby integration ‣ mongo gem ‣ bson/ bson_ext gem ‣ mongo_mapper ‣ mongoid Montag, 31. Mai 2010
  • 58. require 'rubygems' require 'mongo' db = Mongo::Connection.new.db("test") doc = { :text => "You can observe a lot just by watching.", :from => "Yogi Berra", :created_at => Time.now } db['quotes'].insert(doc) db['quotes'].find.each do |row| puts row.inspect end { "_id"=>$oid4bffe2896261046e79000001, "from"=>"Yogi Berra", "created_at"=>Fri May 28 15:34:33 UTC 2010, "text"=>"You can observe a lot just by watching." } Montag, 31. Mai 2010
  • 59. require 'rubygems' require 'mongo' db = Mongo::Connection.new.db("test") 100.times do |i| db['numbers'].insert({"i" => i}) end db['numbers'].find("i" => {"$lt" => 2}).each do |row| puts row.inspect end # {"_id"=>$oid4bffe4396261046f25000001, "i"=>0} # {"_id"=>$oid4bffe4396261046f25000002, "i"=>1} Montag, 31. Mai 2010
  • 60. db['text_entries'].drop_index("tags_1") db['text_entries'].create_index("tags") db['text_entries'].index_information Montag, 31. Mai 2010
  • 62. db = Mongo::Connection.new.db("test") grid = Mongo::Grid.new(db) id = grid.put("You can put Strings in here", :filename => 'test.txt') file = grid.get(id) puts file.filename puts file.read grid.delete(id) grid.put( File.open("/Users/jankrutisch/Dropbox/Photos/IMGP8989.jpg") ) Montag, 31. Mai 2010
  • 63. fs = Mongo::GridFileSystem.new(db) fs.open("test.txt", "w") do |f| f.write "You can put stuff in here" end fs.open("test.txt", "r") do |f| puts f.read end fs.delete("test.txt") Montag, 31. Mai 2010
  • 65. mongo_mapper ‣ By John Nunemaker (@jnunemaker) ‣ works ‣ a few quirks ‣ almost completely undocumented ‣ Some stuff is still missing Montag, 31. Mai 2010
  • 67. # config/initializers/mongo_mapper.rb File.open(File.join(Rails.root, 'config/mongodb.yml'), 'r') do |f| @settings = YAML.load(f)[Rails.env] end MongoMapper.connection = Mongo::Connection.from_uri(@settings["connection"]) if @settings["connection"] MongoMapper.database = @settings["database"] Montag, 31. Mai 2010
  • 68. class Loop include MongoMapper::Document key :name key :public, Boolean key :message_id key :plays_and_downloads, Integer belongs_to :user timestamps! end Montag, 31. Mai 2010
  • 69. @loops = Loop.all( ! :user_id => {"$exists" => true}, ! :order => 'created_at DESC', ! :limit => 10 ) Montag, 31. Mai 2010
  • 72. mongoid ‣ By Durran Jordan (Hashrocket) ‣ Two major versions: ‣ 1.x (currently 1.9) for Rails 2.3 compatibility ‣ 2.x (currently 2.x beta) for Rails 3 compatibility ‣ Good documentation ‣ API is better (?) Montag, 31. Mai 2010
  • 73. File.open(File.join(RAILS_ROOT, 'config/mongodb.yml'), 'r') do |f| @settings = YAML.load(f)[RAILS_ENV] end Mongoid::Config.instance.from_hash(@settings) Montag, 31. Mai 2010
  • 74. class Loop include Mongoid::Document include Mongoid::Timestamps field :name field :public, :type => Boolean field :message_id field :plays_and_downloads, :type => Integer belongs_to_related :user end Montag, 31. Mai 2010
  • 75. Criteria API ‣ A bit like Arel ‣ chainable method calls ‣ Named scopes Montag, 31. Mai 2010
  • 77. class Person include Mongoid::Document field :first_name field :last_name embeds_one :address embeds_many :phones end class Address include Mongoid::Document field :street field :city field :state field :post_code embedded_in :person, :inverse_of => :address end Montag, 31. Mai 2010
  • 80. class Loop include Mongoid::Document include Mongoid::Timestamps include Mongoid::Grid field :name field :public, :type => Boolean field :message_id field :plays_and_downloads, :type => Integer attachment :nan end Montag, 31. Mai 2010
  • 81. using MongoDB 4 real Montag, 31. Mai 2010
  • 83. (if you‘re using Ubuntu) Montag, 31. Mai 2010
  • 85. $ mongod --master or master = true # mongodb.conf $ mongod --slave --source slaveserver.example.com slave = true source = slaveserver.example.com Montag, 31. Mai 2010
  • 92. you‘ve made it this far! Montag, 31. Mai 2010
  • 94. db.text_entries.find({tags: "restaurant"}).limit(10).explain(); { ! "cursor" : "BtreeCursor tags_1", ! "indexBounds" : [ ! ! [ ! ! ! { ! ! ! ! "tags" : "restaurant" ! ! ! }, ! ! ! { ! ! ! ! "tags" : "restaurant" ! ! ! } ! ! ] ! ], ! "nscanned" : 210, ! "nscannedObjects" : 210, ! "n" : 10, ! "millis" : 0, ! [...] } Montag, 31. Mai 2010
  • 96. Extremely easy to grasp Montag, 31. Mai 2010
  • 99. Seems to be very fast Montag, 31. Mai 2010
  • 100. Some issues for small projects Montag, 31. Mai 2010
  • 103. Moi ‣ jan.krutisch@mindmatters.de ‣ http://jan.krutisch.de/ ‣ http://github.com/halfbyte/ ‣ http://twitter.com/halfbyte ‣ http://www.mindmatters.de/ Montag, 31. Mai 2010
  • 104. Pointers ‣ http://www.mongodb.org/ ‣ http://www.mongoid.org/ ‣ http://github.com/jnunemaker/mongo_mapper Montag, 31. Mai 2010