python - Is it a good idea to date as _id when storing time-series data? -
i'm new mongodb. i'm writing python script scrape , update stock quotes data. script run once scrape , build database latest , run everyday updating.
after researching, think mongodb fits bill. currently, i'm setting date '_id' because want ensure uniqueness (since update scrapes page containing data previous days).
is potential disastrous idea? if so, how should otherwise? thanks
no, it's not idea, because, default, mongodb saves timestamp in _id:
you can retrieve _id data using code:
date = new date( parseint( _id.tostring().substring(0,8), 16 ) * 1000 ) i'd use auto-generated mongodb _id
edit: (brought comments) if using pymongo, objectid python object has attribute generation_timefrom can extract related datetime.datetime instance . pymongo api doc
>>> objectid().generation_time
Comments
Post a Comment