rails app mongodb index clarification
In ROR and mongoid as a mapper , i came across this class in model:
class StockPrice
include Mongoid::Document
include Mongoid::Timestamps
field :stock_id, type: String
field :price, type: Float
index :stock_id => +1, :updated_at => -1
def self.price(stock_id)
where(stock_id: stock_id).desc(:updated_at).first.price
end
def self.crawl(stock_id)
# I am stock price from internet using a web crawler
end
end
As a novice to mongodb, I have following doubts:
1)what index is basically used for?
2)what does this line convey in code:
where(stock_id: stock_id).desc(:updated_at).first.price
No comments:
Post a Comment