Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_mongodb.py 617 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  1. from pymongo.mongo_client import MongoClient
  2. import os
  3. from dotenv import load_dotenv
  4. # Load environment variables
  5. load_dotenv()
  6. # Get MongoDB URI from environment variable
  7. uri = os.getenv('MONGODB_URI')
  8. # Check if URI is loaded correctly
  9. if not uri:
  10. raise ValueError("MONGODB_URI is not set in the .env file or not loaded properly.")
  11. # Create a new client and connect to the server
  12. client = MongoClient(uri)
  13. # Send a ping to confirm a successful connection
  14. try:
  15. client.admin.command('ping')
  16. print("Pinged your deployment. You successfully connected to MongoDB!")
  17. except Exception as e:
  18. print(e)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...