MDocument is a simple ORM for MongoDB with addition of relations.
Usage
There are two ways of using mdocument: 1. Specify database, colleciton and client in class. 2. Use modified mongo motor client.
Specifying document parameters in class
import asyncio
import motor.motor_asyncio
from mdocument import MDocument, relations, model
client = motor.motor_asyncio.AsyncIOMotorClient()
class Video(MDocument):
__collection__ = "videos"
__database__ = "mdocument"
__client__ = client
class Model(MDocument.Model):
title = model.Field(str)
views_count = model.Field(int)
public_id = model.Field(str, unique=True)
class Comment(MDocument):
__collection__ = "comments"
__database__ = "mdocument"
__client__ = client
class Model(MDocument.Model):
text = model.Field(str)
video = model.FieldSync(Video, relation=relations.RelationOneToMany, synced_fields=["_id", "title"])
async def main():
video = await Video.create({"title": "Test"})
comment1 = await Comment.create(
video=video._id,
message="First!",
)
comment2 = await Comment.create(
video=video._id,
message="Second!"
)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Now we can easily access our comments using our related documents
TODO: REWRITE DOCUMENTATION!
Metadata
Release files for mdocument 4.0.1612471612
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mdocument-4.0.1612471612.tar.gz | 10.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mdocument-4.0.1612471612-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.9 kB
Release files / mdocument-4.0.1612471612.tar.gz
| Download URL | mdocument-4.0.1612471612.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b569a28b56c9b17e89ad0e0d857346c87c80e9393b7298c838b3966fdfdb0af
|
|
BLAKE2b-256 checksum How to use checksums |
7002940433696fb766b52f993d85d79ed86259c704e0584113cad4e364f62d1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|
Release files / mdocument-4.0.1612471612-py3-none-any.whl
| Download URL | mdocument-4.0.1612471612-py3-none-any.whl |
|---|---|
| Size | 13.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
198119904c05c14de8799a3c30291b463f90da5499587f13524045cbb86966e7
|
|
BLAKE2b-256 checksum How to use checksums |
57bc3788af2ecefef24c2c98f2d6941f07b67fa4cbdc34efb5fce981f98acdae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
|