Rails with mongodb
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Rails with mongodb

on

  • 3,626 views

RailsでMongoDBを利用する

RailsでMongoDBを利用する

Statistics

Views

Total Views
3,626
Views on SlideShare
3,617
Embed Views
9

Actions

Likes
3
Downloads
55
Comments
0

1 Embed 9

http://coderwall.com 9

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Rails with mongodb Presentation Transcript

  • 1. Rails with MongoDB Kosuke Matsuda
  • 2. • MongoDB• Mac MongoDB• Ruby MongoDB• Rails MongoDB
  • 3. MongoDBMongoDB C++ http://ja.wikipedia.org/wiki/MongoDB
  • 4. MongoDB••••• http://www.mongodb.org/display/DOCSJP/Home
  • 5. • RDB• RDB• RDB
  • 6. Mac MongoDB• http://www.mongodb.org/display/DOCS/Downloads• MacPorts $ sudo port install mongodb
  • 7. MongoDB$ sudo mkdir -p /opt/local/var/db/mongodb$ sudo mkdir -p /opt/local/var/log/$ sudo touch /opt/local/var/log/mongodb.log$ /opt/local/bin/mongod --dbpath /opt/local/$ var/db/mongodb --logpath /opt/local/var/log/mongodb.log# /data/db/# Mac http://github.com/AndreiRailean/MongoDB-OSX-Launchctl
  • 8. Ruby MongoDB• mongo-ruby-driver • Official Ruby driver for MongoDB • http://github.com/mongodb/mongo-ruby-driver
  • 9. Set up$ sudo gem install mongo# mongo gem BSON gem$ sudo gem install bson# C$ sudo gem install bson_ext
  • 10. Tutorialrequire "rubygems"require "mongo"db = Mongo::Connection.new.db(test)coll = db.collection("sample")doc = { name => MongoDB, type => database, info => { language => ruby, driver => ruby_driver }}coll.insert(doc)mydoc = coll.find_one()puts mydoc.inspect# {"_id"=>BSON::ObjectID(4c2733f4a27a137051000001), "name"=>"MongoDB","info"=>{"language"=>"ruby", "driver"=>"ruby_driver"}, "type"=>"database"}
  • 11. Rails MongDB• O/R Mapper • MongoMapper • http://mongomapper.com/ • Mongoid • http://mongoid.org/
  • 12. MongoDB• ActiveRecord• Rails Model• SQL-like• http://blog.madoro.org/mn/54
  • 13. Set up• Configuration for Database $ cat config/initializers/database.rb MongoMapper.database = "mongo_sample-#{Rails.env}" if defined?(PhusionPassenger) PhusionPassenger.on_event(:starting_worker_process) do |forked| MongoMapper.connection.connect_to_master if forked end end $ echo "# Using MongoDB" > config/database.yml
  • 14. Set up• Environment # config/environment.rb config.frameworks -= [ :active_record ] config.gem "mongo_mapper"
  • 15. Demo
  • 16. • $ script/generate model ‘ModelName’
  • 17. •• Rails Rails3• MongoDB NoSQL• RDB Rails
  • 18. any questions?