0
{
   {
    "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.

Allen Ye
  • 15
  • 1
  • 3

2 Answers2

1

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.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
0

I would store them like this

 {
  "MSFT2022-01-01" {
    "symbol": "MSFT",
    "close": 0,
    "open": 0,
    "high": 0,
    "low": 0,
    "volume": 0,
    "date": "2022-01-01", 
    "date_to_index": 0
    }, 
  "MSFT2022-01-02" {
    "symbol": "MSFT",
    "close": 1,
    "open": 1,
    "high": 1,
    "low": 1,
    "volume": 1,
    "date": "2022-01-02", 
    "date_to_index": 1
    }
}

That way you can set an index for symbol and date so that its easier to perform find and aggregate queries