Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mongodb mongoid

1,728 views

Published on

  • Be the first to comment

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

×