access mongodb with handy utilities and fun
Project description
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:
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
version 0.1.4
- add
MongoDocumentSchemator
andMongoFieldSchemator
version 0.1.3
- add
TransactionHelper
Project details
Release history Release notifications | RSS feed
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.3.1.tar.gz
(28.5 kB
view details)
File details
Details for the file joker-mongodb-0.3.1.tar.gz
.
File metadata
- Download URL: joker-mongodb-0.3.1.tar.gz
- Upload date:
- Size: 28.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8069fbf4ed03fc5e30d3f3fc7318e0fc62c44c308f8903648fe6bb80560e29ad |
|
MD5 | 25160622572e1985f5f78ee3f358941d |
|
BLAKE2b-256 | 32beb69ee21f6143fe41f154b9ad8b478f94dd6ab354a610d8e6581e7782e80d |