Skip to main content

README

This module provides an easy mechanism to connect to MongoDb.

Currently implemented features -

  1. Provide MongoClient handle
  2. Monitor the MongoClient instance
  3. Log the interactions with Mongodb server
  4. Methods to retrieve details such as username, password, database name, port number and host name for scripts that access database without a database handle.

How to get a mongodb connection?

  1. Import the module into the script
  2. Create an object of the Database class - This will return a class object.

Database Class -

Parameters -

  1. uri = Mongodb URI
mongodb://username:password@host_name:port_number/database_name
  1. logger = Pass a logger handle

  2. log =

     |Option                 |Value                        |
     |-----------------------|-----------------------------|
     |commandlogger          |True | False (Default: True) |
     |serverlogger           |True | False (Default: False)|
     |heartbeatlogger        |True | False (Default: False)|
     |topologylogger         |True | False (Default: False)|
     |connectionpoollogger   |True | False (Default: False)|
    

Get the client handle by calling connect() of the Database class.

Example code -

import mongodb_util

obj = mongodb_util.Database("test_URI")
database_client = obj.connect()
database = database_client.<database name>

Read from a collection

database.<collection_name>.find()

Write into a collection

database.<collection_name>.insert({‘a’:1})

Developing mongodb_util -

To install mongodb_util, along with the tools you need to develop and run tests, run the following in your virtualenv:

$ pip install -e .[dev]

Changelog

  1. Version 1.0 -
  • Provide a mechanism to obtain a mongodb handle
  • Monitoring various transactions with the database
  • Supports custom configuration file.
  1. Version 1.1 -
  • Support for passing logger handle
  1. Version 1.2 -
  • Remove config support
  • Modify the way database credentials are picked, user input expected.
  1. Version 1.3 -
  • Fix Pylint (Pylint version - 1.9.2)

Metadata

Release files for mongodb-util 1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongodb-util 1.3
File Size Uploaded
mongodb_util-1.3.tar.gz 7.8 kB Details

Release files / mongodb_util-1.3.tar.gz

Download URL mongodb_util-1.3.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
23ee824cf22a2ce5061f6df10bb5468c9a70f56c75b58ba169b0ab7efef93338
BLAKE2b-256 checksum
How to use checksums
ff165e8b7a982c9a8132128c765f607ae1f05fd73a080efa33c98862c307a967
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.7.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.5.2

Release history Release notifications | RSS feed

This release

1.3 This release

1 release file

1.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page