Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

ODM

Introduction

The purpose of this module is to do provide easy access to the database with the python object feature with MongoDB and pymongo. With pymongo that was very easy to make spelling mistakes of a collection name when you are doing database operation. This module provides you minimal ODM with a modeling feature so that you don’t have to look up the MongoDB dashboard(Mongo Compass) to know about field names or data types.

Requirement

Since this module is build top of pymongo and pydantic it's good have knowledge about those packages.

Example models

from datetime import datetime
from pymongo import ASCENDING, IndexModel
from pydantic import EmailStr, Field
from typing import Optional

from app.odm.models import Document


class User(Document):
    email: EmailStr = Field(...)
    name: Optional[str] = Field(default=None)
    photo_link: str = Field(default=None)

    password: Optional[str] = Field(default=None)
    last_login: datetime = Field(default_factory=datetime.utcnow)

    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: datetime = Field(default_factory=datetime.utcnow)

    class Config:
        collection_name = "user"
        indexes = [
            IndexModel([("email", ASCENDING)], unique=True),
        ]

Creation

To create an object and call create method. Create method accept one boolean optional argument get_obj. If you want to pull full data and assign to the existing model then call obj.create(get_obj=True) It will recall database with returnd id and update value of existing model.

user = User(
    email="demo@example.com",
    name="Example",
    password="hash-password"
)
user.create()

Retrive Data

users = User.find()
for user in users:
    print(user)

To retrive data there is a function call find. It's return python Iterator. Unless you accessing the value the function will not execute any DB call.

Paramiter of find.

Metadata

Release files for mongodb-odm 0.1a2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongodb-odm 0.1a2
File Size Uploaded
mongodb-odm-0.1a2.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mongodb-odm 0.1a2
File Interpreter ABI Platform
mongodb_odm-0.1a2-py3-none-any.whl Python 3 none any Details

Total release size: 20.0 kB

Release files / mongodb-odm-0.1a2.tar.gz

Download URL mongodb-odm-0.1a2.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c1471aa6139e0e9f3a0856300110c3563eeaeee1b721c5aeb1caea491b32631f
BLAKE2b-256 checksum
How to use checksums
b118598fa34d1b9da44ab8f7d576bc701d584d74c6d3ddddcdbc6e26423a2afe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.6

Release files / mongodb_odm-0.1a2-py3-none-any.whl

Download URL mongodb_odm-0.1a2-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0c4bd8df510cb806a9ebcb9a69f18deb60477cf706a1e03b5586e24950bbf47
BLAKE2b-256 checksum
How to use checksums
e8fd8dac50436073a3fbd39bd19efd5fb626c925227cd9527fbd7c2fc1f61601
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.6

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

This release

0.1a2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page