Skip to content

Instantly share code, notes, and snippets.

@luigi
Created October 11, 2010 21:14
Show Gist options
  • Save luigi/621250 to your computer and use it in GitHub Desktop.
Save luigi/621250 to your computer and use it in GitHub Desktop.
# in mongoid.yml, set autocreate_indexes: true so that the index is created dynamically
$ bin/rails c
Loading development environment (Rails 3.0.0)
irb(main):001:0> class Person
irb(main):002:1> include Mongoid::Document
irb(main):003:1> field :name
irb(main):004:1> field :email
irb(main):005:1> index :name
irb(main):006:1> end
=> {:name=>{:unique=>false}}
irb(main):007:0> Person.create!(:name => "John", :email => "[email protected]")
=> #<Person _id: 4cb37d8229d5fa3003000001, name: "John", email: "[email protected]">
irb(main):008:0> p = Person.last
=> #<Person _id: 4cb37d8229d5fa3003000001, name: "John", email: "[email protected]">
irb(main):009:0> p.name = "Steve"
=> "Steve"
irb(main):010:0> p.save!
=> true
irb(main):011:0> p = Person.last
=> #<Person _id: 4cb37d8229d5fa3003000001, name: "John", email: "[email protected]">
irb(main):012:0> p.email = "[email protected]"
=> "[email protected]"
irb(main):013:0> p.save!
=> true
irb(main):014:0> p = Person.last
=> #<Person _id: 4cb37d8229d5fa3003000001, name: "John", email: "[email protected]">
@luigi
Copy link
Author

luigi commented Oct 12, 2010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment