#mongotokyoのUSTに触発されてとりあえず動くとこまでやってみた

この資料の発表を見てみたんだけど、プロトタイプの作成には凄く良さそうだなぁと。REST-APIを利用して動くクライアント側の実装者がサーバサイドMock作るにはサクサクっと出来そうで夢が広がる。使いこなしとかは考えず使ってみるのは良さそう。

て、訳でとりあえず動かすとこまでやってみました。

インストール & 起動!

$ brew install mongodb
==> Downloading http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-1.8.1.tgz
######################################################################## 100.0%
==> Caveats
If this is your first install, automatically load on login with:
    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/Cellar/mongodb/1.8.1-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

If this is an upgrade and you already have the org.mongodb.mongod.plist loaded:
    launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
    cp /usr/local/Cellar/mongodb/1.8.1-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

Or start it manually:
    mongod run --config /usr/local/Cellar/mongodb/1.8.1-x86_64/mongod.conf
MongoDB 1.8+ includes a feature for Write Ahead Logging (Journaling), which has been enabled by default.
This is not the default in production (Journaling is disabled); to disable journaling, use --nojournal.
==> Summary
/usr/local/Cellar/mongodb/1.8.1-x86_64: 16 files, 93M, built in 2 seconds

Caveatsの指示にしたがって起動。

mongod run --config /usr/local/Cellar/mongodb/1.8.1-x86_64/mongod.conf

Rubyで触ってみる

とりあえずMongoDBのRubyチュートリアルを参考に動かすところまで。

ドライバのインストール

ドライバをgemでインストールする

$ gem install mongodb
$ gem install bson_ext # なんかあるといいよ的な感じで言われたので入れる

で、使ってみる。ruby1.9.2でっす。

# -*- encoding: utf-8 -*-
require 'rubygems'
require 'mongo'

conn = Mongo::Connection.new
db = conn.db('local')
coll = db['testCollection']
coll.insert({name:"cynipe", age:29})
coll.find.each{|row| puts row.inspect}

感想

簡単!!セットアップ〜記事書くまで含めて20分くらいでできちゃった!これからつかっていってみよーっと。