2014-04-13 119 views

回答

1

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会谈论它。