Created
November 23, 2021 23:16
-
-
Save wideglide/30a8f3c8f059848228c85d20fa3ed682 to your computer and use it in GitHub Desktop.
pymongo tutorial
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
#!/usr/bin/env python3 | |
from pprint import pprint | |
from pymongo import MongoClient | |
# Straight from the PyMongo Tutorial | |
# https://pymongo.readthedocs.io/en/stable/tutorial.html | |
## Connection parameters (default for FACT) | |
## need to change the host parameter | |
username = "fact_admin" | |
password = "6fJEb5LkV2hRtWq0" | |
host = "192.168.89.136" | |
port = "27018" | |
db_name = "fact_main" | |
auth_db = "admin" | |
mongo_uri = f"mongodb://{username}:{password}@{host}:{port}/{db_name}?authSource={auth_db}" | |
# Make the connection | |
client = MongoClient(mongo_uri) | |
# Get a database | |
db = client.fact_main | |
# Get a collection | |
file_objects = db.file_objects | |
# Request one document from the collection | |
first_file = file_objects.find_one() | |
# print it! | |
pprint(first_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment