MongoForge
Magic filters for MongoDB
Installation
pip install mongoforge
Basic example
from pymongo import MongoClient
from mongoforge import F
cluster = MongoClient(...)
collection = cluster.db.users
if user := collection.find_one(F._id == 1): # {"_id": 1}
print(user)
else:
collection.insert_one(...)
Additional filters
# Or filter
F.or_f(F.name == "Alex", F.age > 18)
# In
F.name.in_({"Alex", "Bob"})
Available filters
| MongoDB Operator | Python Expression | Example Output |
|---|---|---|
$eq |
F.age == 21 |
{"age": 21} |
$gt |
F.age > 21 |
{"age": {"$gt": 21}} |
$lt |
F.age < 21 |
{"age": {"$lt": 21}} |
$gte |
F.age >= 21 |
{"age": {"$gte": 21}} |
$lte |
F.age <= 21 |
{"age": {"$lte": 21}} |
$or |
F.or_f(...) |
{"$or": [{...}]} |
$in |
F.name.in_(...) |
{"name": {"$in": [...]} |
Like ORM
from typing import Annotated
from pydantic import Field
from pymongo import MongoClient
from mongoforge import F, Q
from mongoforge.orm import Model
cluster = MongoClient("mongodb://localhost:27017")
class User(Model):
id: Annotated[int, Field(..., alias="_id")]
name: Annotated[str | None, Field(None)]
balance: Annotated[int, Field(0)]
class Meta:
collection = cluster.db.users
user = User.one(F.name == "Alex")
if not user:
User.insert(_id=1, name="Alex")
else:
print(user.id, user.name, user.balance)
user.update(Q(balance__inc=100))
Metadata
Release files for mongoforge 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mongoforge-1.2.0.tar.gz | 2.8 kB | Without provenance | Details for mongoforge-1.2.0.tar.gz |
Release files / mongoforge-1.2.0.tar.gz
| Download URL | mongoforge-1.2.0.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35f50f10e821d1c82c1612dfc96a2798267f944fbcb754efb13d385e1742b12f
|
|
BLAKE2b-256 checksum How to use checksums |
87dd06dbdd747439af9950c0974d38a286c7cb366555415bfb2ca9d2e1fcbdd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.0
|
Security for mongoforge 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.