Skip to main content

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

  • pymongo
  • pandas

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mongoautomation_packagenew-0.0.6.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mongoautomation_packagenew-0.0.6-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file mongoautomation_packagenew-0.0.6.tar.gz.

File metadata

File hashes

Hashes for mongoautomation_packagenew-0.0.6.tar.gz
Algorithm Hash digest
SHA256 3f4b0cf56ef2dcbcd717c8618902cd88b4b931eae2430e3da01d80916f300943
MD5 99cb8031c26ae90f240ef895e24d99b0
BLAKE2b-256 c40bf1ccdd78c2ed5908b1f08c8e6860d8dbcce2d038a5b00710e465edc4c8bf

See more details on using hashes here.

File details

Details for the file mongoautomation_packagenew-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for mongoautomation_packagenew-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5261dc78e96cc3e05e81365188fe44c5aa9998525ae61f04c6f723e0db3a5e62
MD5 aee48a932e3ac196fae64db60ecb9d4a
BLAKE2b-256 f08800a0cd4e9c23226bb37bf2e2048e35ea84895878542f767f6a4ea4dba126

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page