Welcome to mongoengine_mate Documentation
mongoengine_mate includes lots more utility method in ORM model Class, makes mongoengine more powerful.
Usage
import mongoengine
from mongoengine_mate import ExtendedDocument
class User(ExtendedDocument):
id = mongoengine.IntField()
name = mongoengine.StringField()
First, you got better __repr__() like:
>>> User(id=1, name="Alice")
User(id=1, name="Alice")
# access its collection or database
>>> col_user = User.col()
>>> col_user.find({"_id": 1})
>>> col_db = User.db()
# access its field name in order
>>> User.fields_ordered()
["id", "name"]
# provide dictionary-like api
>>> user = User(id=1, name="Alice")
>>> user.keys()
["id", "name"]
>>> user.values()
[1, "Alice"]
>>> user.items()
[("id", "name"), (1, "Alice")]
>>> user.to_dict()
{"id": 1, "name": "Alice"}
>>> user.to_OrderedDict()
OrderedDict([("id", "name"), (1, "Alice")])
Smart Insert - Skip Primary Key Conflict
When you do batch insert, sometimes one or a few documents may cause _id field conflict error, which is breaking the batch insert operation.
Usually you have to write a for loop` and use ``try ... except ... to ignore conflict. But, it is SLOW!
ExtendedDocument.smart_insert provides a fast and convenient way to batch insert lots of document at once correctly.
# insert one document which breaks the batch insert
User(id=100, name="Obama").save()
# smart_insert, automatically handle NotUniqueError
User.smart_insert([
User(id=1, name="Alice"),
User(id=2, name="Bob"),
...
User(id=1000, name="Zillow"),
])
Smart Update - Batch Upsert
When you do batch update, you mostly want to use the _id field to locate which document you want to update.
>>>User(id=2, name="Bob").save()
# update only
>>> User.smart_update([
User(id=1, name="Alice"),
User(id=2, name="Bruce"),
User(id=3, name="Cathy"),
], upsert=False)
>>> User.objects.count()
1
# upsert
>>> User.smart_update([
User(id=1, name="Alice"),
User(id=2, name="Bruce"),
User(id=3, name="Cathy"),
], upsert=True)
>>> User.objects.count()
3
Install
mongoengine_mate is released on PyPI, so all you need is:
$ pip install mongoengine_mate
To upgrade to latest version:
$ pip install --upgrade mongoengine_mate
Metadata
Release files for mongoengine-mate 0.0.5
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 |
|---|---|---|---|---|
| mongoengine_mate-0.0.5.tar.gz | 15.8 kB | Without provenance | Details for mongoengine_mate-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mongoengine_mate-0.0.5-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for mongoengine_mate-0.0.5-py2.py3-none-any.whl |
Total release size: 32.6 kB
Release files / mongoengine_mate-0.0.5.tar.gz
| Download URL | mongoengine_mate-0.0.5.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5547085ce7c32f6bba2d3dd30582c4ab2831ab012dca2e2a41ef06c28092a4f4
|
|
BLAKE2b-256 checksum How to use checksums |
0f9387ef53ee7aa6df1ef9ceb50154b1e35ac734ace25b06dc25945f99799c21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/2.7.13
|
Release files / mongoengine_mate-0.0.5-py2.py3-none-any.whl
| Download URL | mongoengine_mate-0.0.5-py2.py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d22176bc9fc8148ef906c4903d586a06de7e0840ffca75377f3054cd0a9fa419
|
|
BLAKE2b-256 checksum How to use checksums |
b280f0f66e698f5e380c3d2999033c3786a84d7c60a6cde492f68f30b707720a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/2.7.13
|
Security for mongoengine-mate 0.0.5
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.