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

问题描述:

因此,我成功地从Bloomberg的OpenAPI中提取请求,并以JSON格式发送数据。我想将这些数据存储在一个MongoDB文档中,该文档将用作查询数据的数据库。任何帮助?谢谢!从Bloomberg API存储JSON数据并将其存储在MongoDB中

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

Ofcourse我不完全确定数据的细节,但这是使用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会谈论它。