MongoRex 🦖
MongoRex is a powerful and easy-to-use Python library that simplifies MongoDB operations. It provides a clean and reusable interface for CRUD operations, indexing, aggregation, transactions, and database management tasks.
Whether you're building a small app or managing large-scale databases, MongoRex makes working with MongoDB effortless.
🚀 Features
✅ Simple CRUD Operations – Easily create, read, update, and delete MongoDB documents.
✅ Index Management – Efficiently create, drop, and list indexes to enhance performance.
✅ Aggregation Pipeline – Perform advanced queries using MongoDB’s aggregation framework.
✅ Transaction Support – Manage multi-document transactions for data integrity.
✅ Bulk Write Support – Streamline operations with batch updates and inserts.
✅ Regex Search – Perform advanced text-based searches with regex support.
✅ Get Latest Documents – Fetch the most recent N documents quickly.
✅ Watch for Changes – Monitor real-time updates in collections.
✅ Database & Collection Stats – Get insights on storage, indexes, and performance.
✅ MapReduce Operations – Execute powerful data transformations and aggregations.
✅ Connection Management – Safely handle and close MongoDB connections.
📦 Installation
Install MongoRex using pip:
pip install MongoRex
Or, install from GitHub (latest version):
pip install git+https://github.com/TraxDinosaur/MongoRex.git
🛠️ Quick Start
Here’s how you can start using MongoRex in your Python application:
1. Initialize MongoRex
from MongoRex import DataBase
# Replace with your MongoDB URI and database name
mongo = DataBase(DB_Name="your_database", MongoURI="mongodb://localhost:27017")
2. Basic CRUD Operations
➕ Add a Document
document = {"name": "Alice", "age": 30}
mongo.add_doc("users", document)
🔍 Find a Document
user = mongo.find_doc("users", {"name": "Alice"})
print(user)
🔄 Update a Document
mongo.update_doc("users", {"name": "Alice"}, {"age": 31})
❌ Delete a Document
mongo.delete_doc("users", {"name": "Alice"})
📚 Full API Reference
📝 CRUD Operations
| Method | Description |
|---|---|
add_doc(collection, document) |
Insert a single document into a collection. |
add_docs(collection, documents) |
Insert multiple documents into a collection. |
find_doc(collection, query) |
Retrieve a single document matching the query. |
find_docs(collection, query, regex_fields=None) |
Retrieve multiple documents with optional regex search. |
update_doc(collection, filter_query, update_data) |
Update a single document matching the filter. |
update_docs(collection, filter_query, update_data) |
Update multiple documents matching the filter. |
update_field(collection, filter_query, field, value) |
Update a single field in a document. |
delete_doc(collection, query) |
Delete a single document matching the query. |
delete_docs(collection, query) |
Delete multiple documents matching the query. |
delete_all(collection) |
Delete all documents in a collection. |
📊 Aggregation & Querying
| Method | Description |
|---|---|
aggregate(collection, pipeline) |
Perform advanced aggregation operations. |
get_latest(collection, limit=5, sort_field="_id") |
Fetch the latest N documents sorted by a field. |
distinct(collection, field, query=None) |
Retrieve distinct values for a specified field. |
map_reduce(collection, map_function, reduce_function, out) |
Perform map-reduce operations on data. |
⚡ Index Management
| Method | Description |
|---|---|
create_index(collection, keys, **kwargs) |
Create an index for a collection. |
drop_index(collection, index_name) |
Drop an existing index. |
list_indexes(collection) |
List all indexes in a collection. |
📁 Database & Collection Management
| Method | Description |
|---|---|
drop_collection(collection) |
Drop a collection from the database. |
list_collections() |
List all collections in the database. |
server_status() |
Retrieve MongoDB server status. |
db_stats() |
Get database statistics. |
collection_stats(collection) |
Retrieve collection statistics. |
🔄 Transactions & Bulk Operations
| Method | Description |
|---|---|
start_session() |
Start a MongoDB transaction session. |
bulk_write(collection, operations) |
Perform bulk write operations. |
👀 Watch for Changes
| Method | Description |
|---|---|
watch(collection=None, pipeline=None) |
Monitor changes in a collection or database. |
🔄 Advanced Document Operations
| Method | Description |
|---|---|
replace_doc(collection, filter_query, replacement) |
Replace a document with a new one. |
rename_collection(old_name, new_name) |
Rename a collection. |
🔌 Connection Management
| Method | Description |
|---|---|
close_connection() |
Close the MongoDB connection safely. |
⚙️ Requirements
- Python 3.6+
pymongolibrary
Install dependencies manually if needed:
pip install pymongo
🛡️ License
MongoRex is licensed under the CC-BY-SA 4.0 license. Feel free to use, modify, and share it, but give appropriate credit.
🏆 Contributors
MongoRex is developed and maintained by TraxDinosaur.
🚀 Contributions are welcome! Feel free to open an issue or submit a pull request on GitHub.
🎯 Get Started Today!
MongoRex simplifies MongoDB operations so you can focus on building great applications.
Start using MongoRex today and enhance your database management experience! 🚀
📌 GitHub Repository: MongoRex on GitHub
Metadata
Release files for MongoRex 1.0.3
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 |
|---|---|---|---|---|
| mongorex-1.0.3.tar.gz | 5.8 kB | Without provenance | Details for mongorex-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| MongoRex-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for MongoRex-1.0.3-py3-none-any.whl |
Total release size: 11.8 kB
Release files / mongorex-1.0.3.tar.gz
| Download URL | mongorex-1.0.3.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5610823c3f35ed6af8a787ebee652f1a2ca32004aab5135c319cb5ae0ec15ef7
|
|
BLAKE2b-256 checksum How to use checksums |
93b7c6074a1b59bdec71451e31e9365523f7a535dc5596037e5987786e0232a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Release files / MongoRex-1.0.3-py3-none-any.whl
| Download URL | MongoRex-1.0.3-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ff5a39403e6d74c9acfdf4bbb10cdb5076dd51003ad7dc1b3bfc61bcffba6dd
|
|
BLAKE2b-256 checksum How to use checksums |
08369fe89bb3b1021fc7e897ac91dae287d29f60d421fe6fbb3b87ea60b5d1af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Security for MongoRex 1.0.3
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.