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!
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mdocument-4.0.1612576120.tar.gz
(10.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdocument-4.0.1612576120.tar.gz.
File metadata
- Download URL: mdocument-4.0.1612576120.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32458bf1dffe2b3d29d39e523b10a563399779c4fe6ebab1ecd0e5051fa671c0
|
|
| MD5 |
c2430b44df8b85b39b99f9b991226de7
|
|
| BLAKE2b-256 |
c613a7c06a90617803225c8c6ea4db79e594919d57cd110bcb94e1175bd54bd1
|
File details
Details for the file mdocument-4.0.1612576120-py3-none-any.whl.
File metadata
- Download URL: mdocument-4.0.1612576120-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b870ea1c80b196c3f017592c04363ad4b7837cc482653645378add50a44a2b1
|
|
| MD5 |
ce608103f436105de7cd523ff97eb9ca
|
|
| BLAKE2b-256 |
09b2fdcf60e893fa1b5246f29ede2e2ef4ad668b80b58534a6205ace01049a2c
|