如何为mongodb创建json对象

时间:2017-01-31 15:51:16

标签: python mongodb pymongo

我正在构建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_infodate创建值并插入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))

请耐心等待,我是一个完全的初学者。

0 个答案:

没有答案