Skip to main content

A PySelfMongo client for the [MongoDB][mongo] database is a thin client that connects to a mongo server and provides a simple interface to the database. A client is written as a singleton to make sure that only one connection is open at a time. The connection timeout is taken care by checking the server info every time a request is made. A new connection is made if the server info is not available or the connection has timed out.

Project description

Py Self Mongo

A self mongo client for the [MongoDB][mongo] database is a thin client that connects to a mongo server and provides a simple interface to the database. A client is written as a singleton to make sure that only one connection is open at a time. The connection timeout is taken care by checking the server info every time a request is made. A new connection is made if the server info is not available or the connection has timed out. The project is developed using poetry and the [Pytest][pytest] framework.

How to use

  1. Create a config file with name .mongo_config.yaml in the root directory of the project. The config file should contain the following fields:
mongo:
  host:
    localhost
  port:
    27017
  db_name:
    db_name
  password:
    password
  username:
    username

The host can be an IP address or a hostname. E.g. In case of a hosted mongo server in aws, the hostname is ec2-*-**-**-**.**-east-2.compute.amazonaws.com. The client can be used as follows:

from pyselfmongo import PySelfMongo

mongo_client = PySelfMongo()
mongo_client.get_collection('collection_name')
  1. If no config file is found, the client will try to connect to the localhost with default port 27017. In this case the client can be intialized as follows:
from pyselfmongo import PySelfMongo

mongo_client = PySelfMongo(db_name='db_name', username='user_name', password='password')
mongo_client.get_collection('collection_name')

Methods and attributes

  • get_collection(collection_name): Returns a collection object.
  • get_document_by_id(collection_name, document_id): Returns a document object.
  • get_document_by_query(collection_name, query): Returns a list of document objects.
  • get_document_by_query_with_projection(collection_name, query, projection): Returns a list of document objects.
  • get_all_document_generatosr(collection_name, filter): Returns a generator of all documents in the collection.
  • delete_document(collection_name, document_id): Deletes a document.
  • delete_document_by_id(collection_name, document_id): Deletes a document.
  • update_document_by_field(collection_name, field, value): Updates a document

Installation

Install using pip:

$ pip install pyselfmongo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PySelfMongo-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

PySelfMongo-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file PySelfMongo-0.1.0.tar.gz.

File metadata

  • Download URL: PySelfMongo-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1021-azure

File hashes

Hashes for PySelfMongo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 81b112885dc536154316e83623c7430d268db8292ad11220b8d4165077c26b6c
MD5 3dfec352101e9ea3e55c168df9d157ff
BLAKE2b-256 17e18e426f6b7e40020a386d6dd11ff865f760a39dbe1df7002c63226a6e2367

See more details on using hashes here.

File details

Details for the file PySelfMongo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: PySelfMongo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1021-azure

File hashes

Hashes for PySelfMongo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a0cce68543f9415e2468151ebc8c9410e0c9bda8c0bd7d9c48f2cb2c5a5f471
MD5 ef3e3a8e1d77440a57b04c8371d4b18e
BLAKE2b-256 c10cc8f25d6fa69f882c2f19e967fdd4acfc67518b7af2663650e68cd1e7c4b1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page