Skip to content

Instantly share code, notes, and snippets.

@squidge
Last active December 25, 2015 09:09
Show Gist options
  • Save squidge/6951574 to your computer and use it in GitHub Desktop.
Save squidge/6951574 to your computer and use it in GitHub Desktop.
Ruby and Mongoid
require 'mongoid'
Mongoid.load!("mongoid.yml", environment = "development")
class Artist
include Mongoid::Document
field :name, type: String
embeds_many :instruments
end
class Instrument
include Mongoid::Document
field :name, type: String
embedded_in :artist
end
syd = Artist.where(name: "Logsie").first
#syd = Artist.create(name: 'Logsie')
syd.instruments.create(name: "Drum")
#syd.with(database: "bands", session: "backup").save!
development:
sessions:
default:
database: test_dev
hosts:
- localhost:27017
options:
#read: strong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment