Insert a dictionary into MongoDB

MongoDB and Python work so well together because Mongo's BSON document structure essentially mirrors a Python dictionary, where we have a range of key/value pairs. 

Here's a very simple example of how to insert a dictionary into MongoDB:

from pymongo import MongoClient

# Create connection to MongoDB
client = MongoClient('localhost', 27017)
db = client['name_of_database']
collection = db['name_of_collection']

# Build a basic dictionary
d = {'website': '', 'author': 'Daniel Hoadley', 'colour': 'purple'}

# Insert the dictionary into Mongo