Skip to content

djmhd/PythonMongoDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# PyMongo Example

Hi! The repo is compose of 3 differents files where 2 are python 3 files and one is a property file.

Files

  • config.properties: Property file where you can add your own host, port, user, password and database name.
  • mongodbconnector.py is a class file containing the code to connect to the DB, and apply crud methods on a collection.
  • testCRUD.py is a unit test class to run to see how to create documents, delete documents and update a document.

Configure the property file

Here is an example of the property file ==>

[MONGODB]
hostPort=clustermehdinfo.lalome1.mongodb.net/
#hostPort=127.0.0.1:27017
user=XXXXXXXXXXXXX
password=XXXXXXXXXXXXX
isCloud=true
queryParam=?retryWrites=true&w=majority
#queryParam=?readPreference=primary&directConnection=true&ssl=false
databaseName=clusterMehdinfo

Change the hostPort, user and password if you have security enabled, query param and databaseName is needed.

Execute type python

Execute the python file "testCRUD.py"

/bin/python3 testCRUD.py 

You should get a result like this ==>

Connecting to mongo:
Connected
Verify that the two records are inserted and then press any key
Verify that the second records is not present anymore and then press any key
.
----------------------------------------------------------------------
Ran 1 test in 5.732s

OK

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages