I need to store daily stock closing prices as well as tick data in MongoDB. How would you design such a schema? For daily prices I would be tempted to have one document for each stock symbol, e.g.
{
symbol: "AAPL",
quotes: {
{
date: '2014-01-01',
values: { open: 1, high: 1, low: 1, close: 1, volume: 100 }
},
{
date: '2014-01-02',
values: { open: 1, high: 1, low: 1, close: 1, volume: 100 }
}, ...
}
}
For tick data I could do something like the above with one subdocument per hour with an array of ticks.
However, considering the maximum document size is only 16MB I believe the limited would be reached very fast, especially for tick data.
I am aware of this approach http://blog.mongodb.org/post/65517193370/schema-design-for-time-series-data-in-mongodb. Would that be a good approach? I.e. one document per symbol per day?
So, how would you design the schema for daily prices and tick data, respectively?
A schema is what defines the structure and contents of your data in visual formats that make it easy for developers and data engineers to keep track of information. Using MongoDB schema designer tools, you can: Maintain data integrity. Store and execute queries efficiency. Know relationships between documents.
Data in MongoDB has a flexible schema. Collections do not enforce document structure by default. This flexibility gives you data-modeling choices to match your application and its performance requirements.
Time Series Data in MongoDB You can create a new time series collection with the createCollection() command. When you want to create a time series collection, you must include the timeField option. timeField indicates the name of the field that includes the date in each document.
I think you are on the right track.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With