存储Bloomberg API中的JSON数据并将其存储在MongoDB中

时间:2014-04-13 00:01:57

标签: json mongodb flask bloomberg

所以我成功地从Bloomberg的OpenAPI中提取请求,数据以JSON格式出现。我想将这些数据存储在MongoDB文档中,该文档将充当将从中查询数据的数据库。对此有何帮助?谢谢!

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

1 个答案:

答案 0 :(得分: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))

这是将JSON文档存储在MongoDB集合中的方法。从MongoDB集合中获取数据非常简单,我确信documentation会对此进行讨论。

相关问题