Created
January 28, 2016 08:28
-
-
Save Kasahs/69c01cbbeaa27cf916f7 to your computer and use it in GitHub Desktop.
Some essential functions for connecting to mongodb, adding data to a collection etc. using pymongo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pymongo import MongoClient | |
def get_db(): | |
try: | |
connection = MongoClient('localhost', 27019) | |
db = connection['db_name'] | |
collection = db['collection_name'] | |
return collection, connection | |
except Exception as e: | |
print(e.__str__()) | |
return None | |
def save_document_to_db(document, collection): | |
collection.insert_one(document) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment