Untitled

mail@pastecode.io avatar
unknown
python
a year ago
632 B
1
Indexable
Never
from pymongo import MongoClient

def get_database():
    # Provide the mongodb atlas url to connect python to mongodb using pymongo
    CONNECTION_STRING = "mongodb+srv://<username>:<password>@<cluster-name>.mongodb.net/myFirstDatabase"

    # Create a connection using MongoClient. You can import MongoClient or use pymongo.MongoClient
    client = MongoClient(CONNECTION_STRING)

    # Create the database for our example 
    db = client['user_shopping_list']
    return db
    
# This is added so that many files can reuse the function get_database()
if __name__ == "__main__":    
    # Get the database
    db = get_database()