Skip to main content

access mongodb with handy utilities and fun

Project description

joker-mongodb

Access mongodb with handy utilities and fun.

Install

From PyPi using pip:

python -m pip install joker-mongodb

Link to current virtual environment for development (run at project root directory):

pip install -e .

Python version requirement (plan)

0.5.0   Python 3.7+
0.6.0   Python 3.7+
0.7.0   Python 3.7+
0.8.0   Python 3.8+
0.9.0   Python 3.9+

Connnect to multiple mongo servers with MongoInterface

Example:

GlobalInterface is defined in example/environ.py as:

from functools import cached_property

import volkanic
from joker.mongodb.interfaces import MongoInterface


class GlobalInterface(volkanic.GlobalInterface):
    package_name = 'example'
    default_config = {
        "mongoi": {
            "local": {},
            "remote": {
                "host": "192.168.22.122",
                "port": 27017
            }
        }
    }

    @cached_property
    def mongoi(self) -> MongoInterface:
        return MongoInterface.from_config(self.conf['mongoi'])

If a configuration file is found at one of the follow locations:

  • Under your project directory in a development enviornment
  • ~/.example/config.json5
  • /etc/example/config.json5
  • /example/config.json5

it will override GlobalInterface.default_config.

Usage in code example/application.py:

from bson import ObjectId
# noinspection PyUnresolvedReferences,PyPackageRequirements
from example.environ import GlobalInterface

gi = GlobalInterface()


def get_product(product_oid):
    coll = gi.mongoi.get_coll('remote', 'example', 'products')
    return coll.find_one({'_id': ObjectId(product_oid)})


if __name__ == '__main__':
    print(get_product('60f231605e0a4ea3c6c31c13'))

Recent changes

See docs/changelog.txt

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

joker-mongodb-0.5.1.tar.gz (31.7 kB view details)

Uploaded Source

File details

Details for the file joker-mongodb-0.5.1.tar.gz.

File metadata

  • Download URL: joker-mongodb-0.5.1.tar.gz
  • Upload date:
  • Size: 31.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.14

File hashes

Hashes for joker-mongodb-0.5.1.tar.gz
Algorithm Hash digest
SHA256 31c14ec2f0439b907b0d4e82419e81392c58eb0d74002ae09a86b109f6bace00
MD5 1e6898be7fd8add754d66f2dbe1b3ac5
BLAKE2b-256 88e1d708a179fe38cdb4d834f3629001d6d22c65d83d02319c1a24e6e200fc50

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