Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python mongodb connection

from pymongo import MongoClient
# pprint library is used to make the output look more pretty
from pprint import pprint

# connect to MongoDB, change the << MONGODB URL >> to reflect 
#your own connection string
client = MongoClient(<<MONGODB URL>>)
db=client.admin
# Issue the serverStatus command and print the results
serverStatusResult=db.command("serverStatus")
pprint(serverStatusResult)

#We can now create a database object referencing a new database, 
#called “business”, as follows:

db = client.business
Source by www.mongodb.com #
 
PREVIOUS NEXT
Tagged: #python #mongodb #connection
ADD COMMENT
Topic
Name
8+5 =