2014-04-13 162 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會談論它。