首页 > 解决方案 > 以日期格式存储日期时间,使用 Pymongo 烧瓶

问题描述

在使用 pymongo 的 Flask 中,我想在 mongodb 中以日期格式存储日期时间,但它使用我编写的代码以数组或字符串格式存储

我的脚本

date_post=time.strftime("%b %d %Y %H:%M:%S %p")  # if i store this in mongo 
                                             db it stores in string datatype
date_post=time.strptime(date_post,"%b %d %Y %H:%M:%S %p")
# if i store this in mongo db it stores in Array datatype
print(type(date_post))


jd = mongo.db.rest_create_job_add

job_id =jd.insert({'Country':country,'State':state,'City':city,'Spoc_Name':spoc_name,'Spoc_EMP_ID':spoc_empid,'SPOC_Email':spoc_email,'Spoc_Mobile_No':spoc_mobile,'Spoc_Work_or_Direct_No':spoc_workno,
    'date_posted':date_post,'band_range':band_range})

在 mongodb 中它存储date_posted在其中,Array datatype而我需要它以日期格式存储。

任何帮助将不胜感激

提前致谢

标签: pythonmongodbpymongo

解决方案


推荐阅读