Hi! The repo is compose of 3 differents files where 2 are python 3 files and one is a property file.
- 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.
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 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