Created
October 22, 2020 20:50
-
-
Save calexandrepcjr/630c6e3c393bc8a2889330997dd2b684 to your computer and use it in GitHub Desktop.
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
import pymongo | |
def mongo_make_client(_mongo_uri): | |
if not _mongo_uri: | |
raise ValueError("MongoURI must have a value") | |
return pymongo.MongoClient(_mongo_uri) | |
def mongo_make_database(_db_name, _mongo_uri=None, _client=None): | |
if not _db_name: | |
raise ValueError("Db name must have a value") | |
if not _mongo_uri and _client is None: | |
raise ValueError("To make the database you must send the MongoURI or the Client") | |
if _client is None: | |
_client = pymongo.MongoClient(_mongo_uri) | |
return _client[_db_name] | |
def mongo_make_collection(_collection_name, _database=None): | |
if not _database: | |
raise ValueError("To make a collection you must send a database instance") | |
return _database[_collection_name] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment