Skip to main content

mongodol

Access MongoDB through a Mapping (dict-like) interface.

mongodol wraps pymongo collections as Mapping/MutableMapping objects (readers and persisters), so you can read and write mongo data with normal dict-like syntax, and compose your own key/value transforms with dol wrappers instead of writing backend-specific boilerplate.

To install:

pip install mongodol

And of course, you need a running MongoDB -- see the installation instructions.

For AI agents

mongodol publishes its documentation in forms made for coding agents. If you are one, start here.

The documentation, machine-readable: llms.txt indexes every page; mongodol.md is the whole documentation in one file; every page has a .md twin; objects.inv maps symbols to URLs.

If you are a control freak, the rest of this README is written for you, starting at Quick start.

Quick start

from mongodol import MongoCollectionPersister, mk_dflt_mgc

# mk_dflt_mgc() gives you a pymongo collection to play with (mongodol/mongodol_test by default)
mgc = mk_dflt_mgc()
mgc.delete_many(
    {}
)  # start from an empty collection (skip this to keep what's already there)
s = MongoCollectionPersister(mgc, getitem_projection={"_id": False})

len(s)
# 0

k = {"_id": "my_id"}
s[k] = {"mongo": "uses", "json": "data"}
list(s)
# [{'_id': 'my_id'}]

Since the base reader is a thin, low-level wrapper, s[k] returns a pymongo.cursor.Cursor (a key may match zero, one, or many docs), so you fetch the value(s) explicitly:

next(s[k])
# {'mongo': 'uses', 'json': 'data'}

del s[k]
len(s)
# 0

Beyond the base classes

The base MongoCollectionReader/MongoCollectionPersister classes always return cursors and never validate uniqueness. For the common case of "one key maps to one doc", use one of the *UniqueDoc*/*FirstDoc* reader and persister classes instead:

from mongodol import MongoCollectionUniqueDocReader

MongoCollectionUniqueDocReader gives you s[k] as a plain dict (not a cursor), and raises KeyNotUniqueError if more than one doc matches k. See its docstring for a runnable example.

For custom key/value shapes, business logic, or connecting mongodol stores to the rest of the dol ecosystem (caching, serialization, key transforms, etc.), wrap a mongodol store with dol.wrap_kvs like you would any other dol store.

More

See the package documentation and the flat mongodol.md aggregate for the full API.

Metadata

Release files for mongodol 0.1.9

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

Source distribution (sdist)

Source distribution for mongodol 0.1.9
File Size Uploaded
mongodol-0.1.9.tar.gz 61.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mongodol 0.1.9
File Interpreter ABI Platform
mongodol-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 130.0 kB

Release files / mongodol-0.1.9.tar.gz

Download URL mongodol-0.1.9.tar.gz
Size 61.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fde53f14636a7deb16407bdcf21acbc5b196f7219f938f67eb83cef769885fe6
BLAKE2b-256 checksum
How to use checksums
d60a32d02abfdcd04bde904c7326f22b38e3210ac87738546eedf7470cefc834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / mongodol-0.1.9-py3-none-any.whl

Download URL mongodol-0.1.9-py3-none-any.whl
Size 68.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2287dcdf7131f8c86c2c0314c95ac0abe3c6f31922c9c0f878c0a9c140c3227
BLAKE2b-256 checksum
How to use checksums
4378c3fa3f18638fa6ff720a0121450ec96e0389ed188835d666488cd0a9e07a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.26

1 release file

0.0.25

1 release file

0.0.24

1 release file

0.0.23

1 release file

0.0.22

1 release file

0.0.21

1 release file

0.0.20

1 release file

0.0.19

1 release file

0.0.18

1 release file

0.0.17

1 release file

0.0.16

1 release file

0.0.15

1 release file

0.0.14

1 release file

0.0.13

1 release file

0.0.12

1 release file

0.0.11

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

2 release files

0.0.2

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