Skip to content

Instantly share code, notes, and snippets.

@wideglide
Created November 23, 2021 23:16
Show Gist options
  • Save wideglide/30a8f3c8f059848228c85d20fa3ed682 to your computer and use it in GitHub Desktop.
Save wideglide/30a8f3c8f059848228c85d20fa3ed682 to your computer and use it in GitHub Desktop.
pymongo tutorial
#!/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