1

I want to store day bay day trading stock data. These data are composite ( ie Price-Volume ) and needs to be mantained in order. How to organize the mongodb data in order to update the data very frequently and reading indexing by equity name,date ? Thanks in advance

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115

1 Answers1

1

You could use a schema something like this:

stocks

{
    _id: "MSFT",
    price: 24.69,
    volume: 53931025,
    date: 20110519
}

Then add indexes over the fields you'll be sorting and filtering by, e.g.

db.stocks.ensureIndex( { date: 1 } )

The _id key field is indexed by default, so updates like this will be very fast:

db.stocks.update( { _id: "MSFT" }, { $set : { price: 25.04 } } )
Chris Fulstow
  • 41,170
  • 10
  • 86
  • 110
  • Great! Since I'm using intraday data, I would happend some additional "Tick" to keep the set ordered, is something special nedded or just adding one index is enough ? – Felice Pollano May 19 '11 at 08:47
  • 1
    That should be enough, if all you're doing is ordering on tick then `db.stocks.ensureIndex( { tick: 1 } )`, if you're not filtering on any other fields apart from _id then you'll be fine. – Chris Fulstow May 19 '11 at 08:55