Created
January 20, 2020 16:17
-
-
Save luminoso/a32d56543ea4ee2cea983b5cde6b8357 to your computer and use it in GitHub Desktop.
quick connnect mongo pymongo
This file contains 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
from pymongo import MongoClient | |
# pprint library is used to make the output look more pretty | |
from pprint import pprint | |
import urllib.parse | |
username = urllib.parse.quote_plus('xx') | |
password = urllib.parse.quote_plus('yy') | |
client = MongoClient(f'mongodb://{username}:{password}@172.31.8.226:27017/') | |
db=client.admin | |
# Issue the serverStatus command and print the results | |
serverStatusResult=db.command("serverStatus") | |
pprint(serverStatusResult) | |
cursor = client.list_databases() | |
for db in cursor: | |
print(db) | |
db = client["anDB"] | |
col = db["anCollection"] | |
x = col.find_one() | |
pprint(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment