SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
43.
> use test
switched to db test
db.quotes.save({
text: "You can observe a lot just by watching.",
from: "Yogi Berra", created_at: new Date()
});
db.quotes.save({
text: "Silence is one of the hardest arguments to refute.",
from: "Josh Billings", created_at: new Date()
});
Sonntag, 22. August 2010
75.
doc = {
:text => "You can observe a lot just by watching.",
:from => "Yogi Berra",
:created_at => Time.now
}
@db['quotes'].insert(doc)
Sonntag, 22. August 2010
76.
doc = @db['quotes'].find_one(id)
doc[:from] = "Yogi Berra, famous baseball player"
@db['quotes'].save(doc)
Sonntag, 22. August 2010
113.
grid = Mongo::Grid.new(@db)
id = grid.put("You can put Strings in here",
:filename => 'test.txt')
file = grid.get(id)
file.filename
file.read
grid.delete(id)
grid.put(
File.open("/Users/jankrutisch/Dropbox/Photos/IMGP8989.jpg")
)
Sonntag, 22. August 2010
114.
fs = Mongo::GridFileSystem.new(db)
fs.open("test.txt", "w") do |f|
f.write "You can put stuff in here"
end
fs.open("test.txt", "r") do |f|
puts f.read
end
fs.delete("test.txt")
Sonntag, 22. August 2010
131.
class Person
include MongoMapper::Document
key :name
one :address
key :tags, Array
end
class Address
include MongoMapper::Document
key :street
key :city
key :country
key :zip
end
Sonntag, 22. August 2010
132.
person = Person.first
address = Person.first.address
Sonntag, 22. August 2010
144.
File.open(File.join(RAILS_ROOT, 'config/mongodb.yml'), 'r') do |f|
@settings = YAML.load(f)[RAILS_ENV]
end
Mongoid::Config.instance.from_hash(@settings)
Sonntag, 22. August 2010
146.
class Quote
include Mongoid::Document
include Mongoid::Timestamps
field :from
field :text
field :views, :type => Integer
end
Sonntag, 22. August 2010
150.
class Person
include Mongoid::Document
field :name
embeds_one :address
field :tags, :type => Array
end
class Address
include Mongoid::Document
field :street
field :city
field :country
field :zip
end
Sonntag, 22. August 2010
151.
person = Person.first
address = Person.first.address
Sonntag, 22. August 2010