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.
- 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.
Install the package via pip:
pip install mongoautomation_packagenewHere's a quick guide to get started with the package:
from mongoautomation_packagenew import mongo_operationInitialize the MongoDB operations:
mongo_ops = mongo(
client_url="mongo_url",
database_name="my_database",
collection_name="my_collection"
)mongo_ops.insert_record({"name": "Aliya", "age": 25}, "example_collection")records = [{"name": "Bob", "age": 25}, {"name": "Charlie", "age": 28}]
mongo_ops.insert_record(records, "my_collection")Insert records from a CSV or Excel file:
mongo_ops.bulk_insert("data.csv", "my_collection")mongo_ops.update_record(
query={"name": "Alice"},
update_data={"age": 35},
collection_name="my_collection"
)mongo_ops.update_record(
query={"age": {"$lt": 30}},
update_data={"status": "young"},
collection_name="my_collection",
update_all=True
)mongo_ops.delete_record(
query={"name": "Charlie"},
collection_name="my_collection"
)mongo_ops.delete_record(
query={"age": {"$lt": 25}},
collection_name="my_collection",
delete_all=True
)mongo_ops.set_new_database("new_database")mongo_ops.set_new_collection("new_collection")- Python 3.8+
- MongoDB Server
pymongopandas