0

I am thinking of two structures, I don't know which is better or is there are better structure? Im seeking your advise

  1. Normal structure with code as id and time as string
{
    "_id": "AAPL-20220112",
    "code": "AAPL",
    "trade_date": "20220112",
    "open": 17.41,
    "high": 17.45,
    "low": 16.9,
    "close": 17,
    "pre_close": 17.41,
    "change": -0.41,
    "pct_chg": -2.355,
    "vol": 1502163.55,
    "amount": 2561266.412
}
  1. TimeSeries Structure
{
    "datetime": {
        "$date": "2022-01-26T09:31:00.000Z"
    },
    "low": 16.91,
    "order_book_id": "AAPL",
    "open": 16.95,
    "high": 17.08,
    "num_trades": 1994,
    "total_turnover": 46092284,
    "volume": 2713640,
    "_id": {
        "$oid": "61f12c8adae836919ca6c665"
    },
    "close": 17.01
}

When work with stocks, I upload data using "update" command, so that repeated data will not be inserted.

And, when pulling data, I use time or stock as index. But hoping the time be already ranked by the database. Using time like string will be hard to rank.

Any suggestions?

2
  • or store time as timestamp in int form?
    – George
    Jan 27 at 0:53
  • (1) In general, its best to store time (date/time) as a MongoDB date data type. It allows many advantages - date comparison for sorting, range queries, date arithmetic, and you can get any of the date fields (month, day, year, hour, etc.) from the date field to further work with using date operators. (2) The structure of the data depends upon many factors, mainly, the use case / the application (the kind of operations performed - the important ones), and the amount of data. This is addressed thru the process of Data Modeling.
    – prasad_
    Feb 2 at 10:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.