【问题标题】:Storing JSON data from Bloomberg API and storing it in MongoDB从 Bloomberg API 存储 JSON 数据并将其存储在 MongoDB 中
【发布时间】:2014-04-13 00:01:57
【问题描述】:

所以我成功地从 Bloomberg 的 OpenAPI 拉取请求,并且数据以 JSON 格式输出。我想将此数据存储在一个 MongoDB 文档中,该文档将充当从中查询数据的数据库。有什么帮助吗?谢谢!

其他一些信息:我正在尝试设置一个使用 PyMongo 的烧瓶文档以填充数据库。

【问题讨论】:

    标签: json mongodb flask bloomberg


    【解决方案1】:

    当然,我并不完全确定数据的细节,但这是使用pymongo 与 MongoDB 交互的一般流程。

    import json
    from pymongo import MongoClient
    
    # Create a connection to the mongodb instance. Passing no parameters will connect to default host (localhost) and port (27017)
    connection = MongoClient()
    
    # Store the database reference in a variable
    db = connection.bloomberg
    
    # Get the collection
    collection = db.<whatever-you-want-the-collection-name-to-be>
    
    # Assuming the response of the API is a json string in a variable line
    collection.insert(json.loads(line))
    

    这是您在 MongoDB 集合中存储 JSON 文档的方式。从 MongoDB 集合中获取数据是直截了当的,我相信 documentation 会谈论它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多