Mongodb mongoid

1,722 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,722
On SlideShare
0
From Embeds
0
Number of Embeds
816
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Mongodb mongoid

  1. 1. MongoDBfrom MongoidIng. Marcos Vanetta@malevhttp://blog.malev.com.arThree Pillar Global
  2. 2. MongoDB from MongoidMongoDB: (from "humongous") is a scalable,high-performance, open source, document-oriented database.Mongoid: Mongoid (pronounced mann-goyd) isan Object-Document-Mapper (ODM) forMongoDB written in Ruby.
  3. 3. The philosophy of Mongoid is to provide afamiliar API to Ruby developers who have been using Active Record or Data Mapper
  4. 4. class User include Mongoid::Document field :name, :type => String field :email, :type => String #...
  5. 5. class User include Mongoid::Document field :name, :type => String field :email, :type => String field :phone, :type => String #...
  6. 6. class User include Mongoid::Document field :name, :type => String field :email, :type => String field :phone, :type => String field :tags, :type => Array field :info, :type => Hash #...
  7. 7. class User include Mongoid::Document field :name, :type => String field :email, :type => String field :auto_approved, :type => Boolean field :message, :type => String field :phone, :type => String embeds_many :devices
  8. 8. class User include Mongoid::Document field :name, :type => String field :email, :type => String field :auto_approved, :type => Boolean field :message, :type => String field :phone, :type => String embeds_many :devices has_many :cars
  9. 9. @user = User.first@user = User.find(params[:id])@users = User.where(:phone => “123”)@users = @users.any_of({name: /abc*/i})@user = User.where({"devices.token"=>”ff”})@user.devices.where({token: params[:t]})Person.where(:title.all => ["Sir"])Person.where(:title.in => ["Sir", "Madam"])
  10. 10. Also has● Validations● Callbacks● Index● Scopes● Paranoid● Versioning (not so good)● Timestamps
  11. 11. Migrationshttp://github.com/adacosta/mongoid_rails_migrations
  12. 12. At first it seems to be a sh*# But it works!
  13. 13. Questions? @malev

×