Keynote from the first Fullstack: Ruby on Rails meetup hosted by General Assembly.
Presentation about how Rails and MongoDB fit together naturally and how to use MongoDB with Rails through the Mongoid ODM.
http://www.meetup.com/FullStack-General-Assembly-NYC-Ruby-on-Rails/events/107952222/
3. Ruby engineer on the drivers team
art historian
consultant
adjunct faculty
at Columbia
web (Rails) developer
4. Learning Rails is unconventional
you have to be resourceful
○ example projects
○ online tutorials
○ community
5. Rails has conventions
DSL ActiveRecord
convention over rvm
configuration bundler
blackboxed gems community
DRY MVC
All http stuff was github
written already
6. ActiveRecord
● ActiveRecord bridges the gap between
OOP and a relational database
● mongodb is OO natively
● Rails was built for a relational database
7. what is ?
MongoDB comes from the word ______.
It is a ______ database that is highly
______ and released under the ______
license, making it ______.
It stores data in ______ format and is
often favored for the ______ experience
because it is ______.
8. What is Ruby?
Ruby was created by ______.
Ruby is extremely ______ and ______ to
use.
It is known for seeing everything as an
______ and for the ______ experience.
9. What is a mongodb driver?
1. connection pooling
2. serialization/deserialization
BSON<->hashes
3. wire protocol
4. classes for server stuff
ex: abstracts RS, sharded cluster
https://github.com/mongodb/mongo-ruby-driver/
16. ODM: Mongoid
How do we get Ruby, Rails, and
MongoDB to work together?
Object Document Mapper available
as a gem
Used to be community ODM, with its
own driver
17. User and Favorite
model files
class User
include Mongoid::Document
field :name, type: String
field :age, type: Integer
field :langs, type: Array
has_many :favorites
end
class Favorite
include Mongoid::Document
field :artists, type: Array
field :color, type: String
field :movies, type: Array
belongs_to :user
end
19. User and Favorite
model files
class User
include Mongoid::Document
field :name, type: String
field :age, type: Integer
field :langs, type: Array
embeds_one :favorite
end
class Favorite
include Mongoid::Document
field :artists, type: Array
field :color, type: String
field :movies, type: Array
embedded_in :user
end
20. Docs in MongoDB
# The user info and favorites in a single document
{
"_id" : ObjectId("512e8fdab074c63e71dc6500"),
"name" : "Emily",
"age" : 28,
"langs" : ["Ruby", "Python", "C++"],
"favorite" : {
"artists" : ["George Bellows", "Rodin"],
"color" : "Blue",
"movies" : ["Old Boy", "Gladiator"],
}
}
21. Thanks!
Keep using resources and the community
Check out the ruby driver and submit a pull
request
https://github.com/mongodb/mongo-ruby-driver/
Try out mongoDB and Mongoid
Emily Stolfo
@EmStolfo