我正在构建json对象,我希望使用pymongo
将数据插入到mongoldb中已存在的集合中。数据如下所示:
[
{
"title": "PyMongo",
"publication_date": "2015-09-07 10:00:00",
"tags": ["python", "mongodb", "nosql"],
"author": {
"name": "David",
"author_info": {
"$oid": "1870981708ddb1a352189e25w"
},
},
"date": {
"$date": 1484071215000 },
}
]
我注意到作者有objectid而日期是时间戳,我如何为author_info
和date
创建值并插入mongodb?
我有一个构建如下值的函数:
def build_json(title, pubctndate,taglist,author):
json_ob = \
[ {
"title": title,
"publication_date": pubctndate,
"tags": tablets,
"author": {
"name": author,
"author_info": {
"$oid": " "
},
},
"date": {"$date": },
}]
return json_ob
我打算这样称呼json.dumps(build_json(title, pubctndate,taglist,author))
请耐心等待,我是一个完全的初学者。