Deepender Singla
Deepender Singla

Reputation: 997

Rails app and mongdb database code Explain

I am new to mogodb and forked one rails app which use Mongoid - 3.00 as mapper. Now one of my model is this :

class Portfolio
 include Mongoid::Document
 include Mongoid::Timestamps

  """
  Folder format:
  {
   name: <folder name>,
   stocks: [
    {
       name: <stock name>,
      id: <stock id>,
      qty: <stock quantity>
     }
    ]
  }
  """
  field :folders, type: Array
  end

I am running rails app like this : 1) bundle and 2) rails s

I have some doubts
1)Right now model are independent , Suppose if I can see the database in the mongodb shell how i can see different fields declared in the database?
2)In the above code what is the function of code between """ and """.?

Upvotes: 0

Views: 93

Answers (1)

Pierre-Louis Gottfrois
Pierre-Louis Gottfrois

Reputation: 17631

Not sure about the code between """ but you simply do this to add attributes to your model using mongoid:

class Portfolio
 include Mongoid::Document
 include Mongoid::Timestamps

 field :a_string, type: String, default: ''
 field :an_integer, type: Integer, default: 0
 field :a_hash, type: Hash, default: {}
end

From mongodb shell:

> mongo
> use your_database_name
> db.portfolios.findOne()

More information on mongoid here

More information on mongodb here

Upvotes: 1

Related Questions