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.2.0   Python 3.6+
0.3.0   Python 3.7+
0.4.0   Python 3.8+
0.5.0   Python 3.9+
0.6.0   Python 3.10+

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

joker_mongodb-0.5.0-py3-none-any.whl (36.6 kB view details)

Uploaded Python 3

File details

Details for the file joker_mongodb-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for joker_mongodb-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 589fa2a8d46a318a775a249cd5b7ce612bf28689eebcd24ca1bd5edccf4ffc61
MD5 24b8e78a431dc48133156a2eee089349
BLAKE2b-256 2d1a898b86815d4c6ce45de2309fc598b9cf16bf76160207221c22aeb8714d1f

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