Rails 3 + MongoDB ã®ã¡ã¢
CouchDB definitive guide ãå±ããã¿ã¤ãã³ã°ã§ MongoDB ã«ä¹ãæãã¦ãã¾ããRails 3 ã¨å
±ã«æ¯ãä¸ã
æç« ãåæ£ãã¦ãããæ¬ ãã¦ãããããã®ã§ã¡ã¢ãæ®ãã¦ã¿ãã
Gemfile
gem "bson_ext" gem "mongoid", ">= 2.0.0.beta2"
run generator
g mongo:config g mongo:entry
ãã®æç¹ã§ mongod ã«ã¢ã¯ã»ã¹ãå ¥ãããã«ãªãï¼ãã¶ãï¼ã
entry.rb
class Entry include Mongoid::Document include Mongoid::Timestamps field :title field :slug field :body end
AR ã§ä½¿ã£ã¦ãã fixture ãããã®ã§æå ¥ããã
# rails console YAML.load(File.read(Rails.root+"test/fixtures/entries.yml")).each{|idx, data| Entry.new(data).save! }
Entry.count ãã¦ã¿ãã¨ã«ã¦ã³ããåããã
mongod ã®ãã°ã«ããããããã®ãæ®ã£ã¦ããã
mongo ã³ã³ã½ã¼ã«ã«ã¦
> db.entries.find().forEach(function(o) { print(o.title); }) MyString3 MyString-1year-ago MyString4 MyString5 MyString-latest
åãããEntry -> entries ã«ãªã£ã¦ããã®ã«æ³¨æã
mongo
- db.your_obj.stats ã§èª¿æ»ãno ns ã¯ãã¼ã¿ä¸å¨ï¼å¤§æµã¯ãªãã¸ã§ã¯ãåéãï¼
- ã³ã³ã½ã¼ã«ã¯ js ãªã®ã§
- for (var key in db.your_obj) { print(key); } 㧠enum ãªã¡ã³ããããªã³ãåºæ¥ãã
ã½ã¼ã¹ã¯ github ã«ã