Intro to Mongoid

Mongoid: object-document-mapper(ODM) 

Mongoid Configuration: 

rails g mongoid:config 

 

Document: 

Documents are the core objects in Mongoid ---- Mongoid::Document 

Doucuments can be stored in a collection or embedded in other documents 

 

Fields are attributes -- type String by default 

class Movie 
    include Mongoid::Document 
    field :title, type: String 
end 

 

Field Aliases: 

field :birthName, as: :birth_name, type: String 

 

store_in: 

class Location 
    include Mongoid::Document 
    store_in collection: "Places"
    field :city, type: String 
end 

# Location gets stored in to "places" collection 

 

posted @ 2019-04-29 21:30  vixennn  Views(164)  Comments(0)    收藏  举报