Skip to main content

Extended mongoengine

Project description

Depends on environment variables:

  • MONGO_DB (Required)
  • MONGO_HOST (Optional)
  • MONGO_PASSWORD (Optional)
  • MONGO_USER (Default: "root")
  • MONGO_PORT (Optional)

Example:

from datetime import datetime, date

from bson import ObjectId

from mongo import Document, PrimaryKey


class Doc(Document):
    key: int | PrimaryKey
    a1: str  # Required
    a2: int | None
    a3: bool | None
    a4: float | None
    a5: ObjectId | None
    a6: datetime | None
    a7: date | None
    b1: list[str]
    b2: list[int]
    b3: list[bool]
    b4: list[float]
    b5: list[ObjectId]
    b6: list[datetime]
    b7: list[date]
    c1: dict


KEY = 0
A1 = "a1"

d = Doc(key=KEY, a1=A1).save()

assert Doc.get(KEY) == d
assert Doc.find(a1=A1) == d
assert Doc.find_all(a1=A1) == [d]
assert d.str_id == str(KEY)
assert d.to_dict() == {
    "_id": KEY,
    "a1": A1,
    "b1": [],
    "b2": [],
    "b3": [],
    "b4": [],
    "b5": [],
    "b6": [],
    "b7": [],
    "c1": {},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ext-mongo-0.4.0.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

ext_mongo-0.4.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

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