Home > database >  MongoDB: Can I store stock data in this way?
MongoDB: Can I store stock data in this way?

Time:07-30

{
   {
    "symbol": "MSFT",
    "close": [0, 1, 2, 3, 4, 5],
    "open": [0, 1, 2, 3, 4, 5],
    "high": [0, 1, 2, 3, 4, 5],
    "low": [0, 1, 2, 3, 4, 5],
    "volume": [0, 1, 2, 3, 4, 5],
    "dates": ["2022-01-01", "2022-01-02", "2022-01-03", "2022-01-04", "2022-01-05", "2022-01-06"],
    "date_to_index": {
        "2022-01-01": 0,
        "2022-01-02": 1,
        "2022-01-03": 2,
        "2022-01-04": 3,
        "2022-01-05": 4,
        "2022-01-06": 5
    }
}

when I need the data of MicroSoft from 2022-01-03 to 2022-01-05, I will get the start and end indices from date_to_index and then retrieve the slice from index 2 to index 4 of the data arrays I want.

CodePudding user response:

You can certainly store data this way, but

  1. looks you'll need to fetch the entire object each time you want to extract only a part of data or do two queries. Either way, it looks not ideal.
  2. Gut feeling says there's a risk of not fitting into document size limit when using real world data (MSFT, for example, has decades of stock data history). Having sub-day resolution increases this risk even further.

Overall, I'd explore alternate strategies.

  • Related