Created
September 27, 2012 11:39
-
-
Save vladzloteanu/3793566 to your computer and use it in GitHub Desktop.
Mongoid persistence mode (fire and forget by default)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModel | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
field :value, :type => String | |
index :value, :unique => true | |
attr_accessible :value | |
end | |
MyModel.delete_all | |
MyModel.create_indexes | |
5.times{|t| puts MyModel.create!({:value => 'myvalue'}).inspect } | |
# #<MyModel _id: 50643bbc654af19b4a000093, value: "myvalue", updated_at: Thu Sep 27 11:42:52 UTC 2012, created_at: Thu Sep 27 11:42:52 UTC 2012, _type: nil> | |
# #<MyModel _id: 50643bbc654af19b4a000094, value: "myvalue", updated_at: Thu Sep 27 11:42:52 UTC 2012, created_at: Thu Sep 27 11:42:52 UTC 2012, _type: nil> | |
# #<MyModel _id: 50643bbc654af19b4a000095, value: "myvalue", updated_at: Thu Sep 27 11:42:52 UTC 2012, created_at: Thu Sep 27 11:42:52 UTC 2012, _type: nil> | |
# #<MyModel _id: 50643bbc654af19b4a000096, value: "myvalue", updated_at: Thu Sep 27 11:42:52 UTC 2012, created_at: Thu Sep 27 11:42:52 UTC 2012, _type: nil> | |
# #<MyModel _id: 50643bbc654af19b4a000097, value: "myvalue", updated_at: Thu Sep 27 11:42:52 UTC 2012, created_at: Thu Sep 27 11:42:52 UTC 2012, _type: nil> | |
# => 5 | |
MyModel.all.to_a | |
# => [#<MyModel _id: 50643a81654af19b4a00000c, value: "myvalue", updated_at: Thu Sep 27 11:37:37 UTC 2012, created_at: Thu Sep 27 11:37:37 UTC 2012, _type: nil>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment