A python package for connecting with database.
Project description
Mongo_DB_Connector_PYPI_Package
A Python library to simplify MongoDB operations like creating databases, collections, inserting, updating, and deleting records, and performing bulk operations with CSV and Excel files.
Features
- Easily create and switch between databases and collections.
- Insert single or multiple records.
- Perform bulk inserts from CSV or Excel files.
- Update single or multiple records with ease.
- Delete single or multiple records.
- Support for custom queries using MongoDB's query syntax.
Installation
Install the package via pip:
pip install mongoautomation_packagenew
Usage
Here's a quick guide to get started with the package:
1. Import and Initialize
from mongoautomation_packagenew import mongo_operation
Initialize the MongoDB operations:
mongo_ops = mongo(
client_url="mongo_url",
database_name="my_database",
collection_name="my_collection"
)
2. Insert Records
Insert a Single Record
mongo_ops.insert_record({"name": "Aliya", "age": 25}, "example_collection")
Insert Multiple Records
records = [{"name": "Bob", "age": 25}, {"name": "Charlie", "age": 28}]
mongo_ops.insert_record(records, "my_collection")
3. Bulk Insert from File
Insert records from a CSV or Excel file:
mongo_ops.bulk_insert("data.csv", "my_collection")
4. Update Records
Update a Single Record
mongo_ops.update_record(
query={"name": "Alice"},
update_data={"age": 35},
collection_name="my_collection"
)
Update Multiple Records
mongo_ops.update_record(
query={"age": {"$lt": 30}},
update_data={"status": "young"},
collection_name="my_collection",
update_all=True
)
5. Delete Records
Delete a Single Record
mongo_ops.delete_record(
query={"name": "Charlie"},
collection_name="my_collection"
)
Delete Multiple Records
mongo_ops.delete_record(
query={"age": {"$lt": 25}},
collection_name="my_collection",
delete_all=True
)
6. Advanced Features
Set a New Database
mongo_ops.set_new_database("new_database")
Set a New Collection
mongo_ops.set_new_collection("new_collection")
Requirements
- Python 3.8+
- MongoDB Server
Dependencies
pymongopandas
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mongoautomation_packagenew-0.0.8.tar.gz.
File metadata
- Download URL: mongoautomation_packagenew-0.0.8.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88b49b182ba2f3813131fac6f7fd3c442ae25ecabaf3b1666ddd65ef165ee503
|
|
| MD5 |
b554c713078292a86af355fb671ea0c3
|
|
| BLAKE2b-256 |
354d19f5888c315a47f4ca0ea321e5c03441c53c0d01775ef4a7163994faaefc
|
File details
Details for the file mongoautomation_packagenew-0.0.8-py3-none-any.whl.
File metadata
- Download URL: mongoautomation_packagenew-0.0.8-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfa309b5672ea8afc59e7fc71a52fec64249c8fb2907daa1ed672539a445899e
|
|
| MD5 |
cdb10639b33eb2e3b2d093058044fec9
|
|
| BLAKE2b-256 |
7e960439fb94713bacef2cb656829e22d7c5578b46d82d3e229cacc7ff7f42d0
|