Metadata-Version: 2.1
Name: joker-mongodb
Version: 0.3.0
Summary: access mongodb with handy utilities and fun
Home-page: https://github.com/frozflame/joker-mongodb
Author: frozflame
Author-email: frozflame@outlook.com
License: GNU General Public License (GPL)
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.7.0
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: joker-cast>=0.5.0
Requires-Dist: joker-textmanip>=0.3.1
Requires-Dist: joker>=0.3.3
Requires-Dist: pymongo>=3.11.0
Requires-Dist: volkanic>=0.5.1

joker-mongodb
=============

Access mongodb with handy utilities and fun.

## Connnect to multiple mongo servers with MongoInterface

Example:

`GlobalInterface` is defined in `example/environ.py` as:

```python
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`:

```python
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
--------------

version 0.1.4

* add `MongoDocumentSchemator` and `MongoFieldSchemator`

version 0.1.3

* add `TransactionHelper`

