Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

mongodb connection using python

	#PreRequisite install pymono
	#pip install pymongo
	from pymongo import MongoClient
  
  	# connect to MongoDB, change the << MONGODB URL >> if connection details are different
  	client = MongoClient("mongodb://127.0.0.1:27017")
    print("Connection Successful")
    
    db=client.admin
    # Issue the serverStatus command and print the results
	serverStatusResult=db.command("serverStatus")
    
    #We can now create a database object referencing a new database, 
	#called “business”, as follows:
	db = client.business
    
    # Create the database for our example (we will use the same database throughout the tutorial
    return client['user_shopping_list']
    
# This is added so that many files can reuse the function get_database()
if __name__ == "__main__":    
    
    # Get the database
    dbname = get_database()
    
    client.close()
Source by www.mongodb.com #
 
PREVIOUS NEXT
Tagged: #mongodb #connection #python
ADD COMMENT
Topic
Name
3+8 =