Connect to MongoDB

This snippet demonstrates how to connect to a local instance of MongoDB.

#import pymongo
from pymongo import MongoClient

# Set up the client, by default MongoDB runs on port 27017
client = MongoClient('localhost', 27017)

# Set the name of the MongoDB database you want to connect to
db = client['name_of_database']

# Set the name of the collection within the database you want to connect to
collection = db['name_of_connection']