MongoDB fields Cleaner
It simplifies the process of cleaning up old deprecated fields in a MongoDB database.
This will help you to easily remove obsolete/unused fields in your MongoDB collections so that you can save space in your DB.
How to use it
It is as simple as getting a pymongo.MongoClient and pass it to the Cleaner constructor.
Once we have the Cleaner object instance, we just need to call the clean method with the collection name and the field names we want to keep (unset), the fields not in this collection will be removed. This call will return an UpdateResult object.
from mdb_fields_cleaner import Cleaner
client = MongoClient()
cleaner = Cleaner(client)
results: UpdateResult = cleaner.clean(collection.name, ["make", "model"])
print(f"{results.modified_count} modified documents")
Data models
You can use following convenience cleaners to just remove any field in a collection that is not defined in the model.
dataclasses
from pydantic import BaseModel
from mdb_fields_cleaner.dataclass import DataClassCleaner
from dataclasses import dataclass
@dataclass
class User:
id: int
name: str
cleaner = DataClassCleaner(MongoClient())
results: UpdateResult = cleaner.clean_fields_not_in_model("users_collection", User)
print(f"{results.modified_count} modified documents")
Pydantic Models
from pydantic import BaseModel
from mdb_fields_cleaner.pydantic import PydanticCleaner
class User(BaseModel):
id: int
name: str
cleaner = PydanticCleaner(MongoClient())
results: UpdateResult = cleaner.clean_fields_not_in_model("users_collection", User)
print(f"{results.modified_count} modified documents")
Development flow
- Create a branch and a pull request.
- Label the pull request with the correct semver label: patch, minor, major.
- Get the PR approved and merged.
At this point the package should be published in Pypi.org registry.
Metadata
Release files for mdb-fields-cleaner 0.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 | |
|---|---|---|---|---|
| mdb_fields_cleaner-0.2.0.tar.gz | 3.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mdb_fields_cleaner-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.2 kB
Release files / mdb_fields_cleaner-0.2.0.tar.gz
| Download URL | mdb_fields_cleaner-0.2.0.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3ead50dfb9b8d4c946f00fb0737c4b1e7699446ab3bf3302d22e1b76b48de580
|
|
BLAKE2b-256 checksum How to use checksums |
07eeef9bb8643f3445760bb88498534fdec2cfb573c8f92e53d4785ecdd16254
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / mdb_fields_cleaner-0.2.0-py3-none-any.whl
| Download URL | mdb_fields_cleaner-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59457d770b5463c608f16587e28014e845e87f5c5325d9164134d020c80f31e8
|
|
BLAKE2b-256 checksum How to use checksums |
fa9546d8fb8f9e06113a23fe6adcd1dea271e0390636a30614346f710f8ed416
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for mdb-fields-cleaner 0.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.