Skip to main content

A python package for connecting with database.

Project description

Overview

mdb_connect_pkg is a Python package designed to simplify the process of connecting to and interacting with MongoDB databases. This package provides a streamlined API for performing CRUD (Create, Read, Update, Delete) operations, handling connections, and managing MongoDB collections with ease.

Features

  • Easy connection management to MongoDB instances

  • Simple CRUD operations

  • Handling of MongoDB collections

Directory Structure

mongodb-connector-pkg/
├── .github/
│   └── workflows/
│       └── ci.yaml
│       └── python-publish.yaml
├── src/
│   └── mdb_connect_pkg/
│       └── mongo_crud.py
├── tests/
│   ├── unit/
│   │   └── test_unit.py
│   └── integration/
│       └── test_integration.py
├── .gitignore
├── init_setup.sh
├── LICENSE
├── pyproject.toml
├── README.md
├── README.rst
├── requirements_dev.txt
├── requirements.txt
├── setup.cfg
├── setup.py
├── template.py
└── tox.ini

How to Use This Package

Installation

To install the package, use pip:

pip install mdb-connect-pkg==1.1.1

Usage

Connecting to MongoDB

First, import the package and create a connection instance:

# Importing the package
from mdb_connect_pkg import mongo_crud

# Initialize the connector
db_connection_url = 'mongodb://localhost:27017'
database_name = 'mydatabase'
collection_name = 'mycollection'
mongo = mongo_crud.MongoDBConnection(db_connection_url, database_name, collection_name)

# Creating the client and connect to the database
mongo.create_mongo_client()
mongo.database_()
mongo.collection_()

CRUD Operations

Create

To insert a single record into the collection:

mongo.single_insert({"name": "John Doe", "age": 30, "email": "johndoe@example.com"})

To insert a JSON file into the collection:

json_file_path = 'example.json'
mongo.bulk_insert(json_file_path)

To insert a CSV file into the collection:

csv_file_path = 'example.csv'
mongo.bulk_insert(csv_file_path)

Read

To load the data from the MongoDB database to a pandas DataFrame:

df = mongo.load_data()
df.head()

Update

To update the records in the collection:

mongo.update_data({"name": "John Doe"},{"$set": {"age": 31}})

Delete

To delete records in the collection:

mongo.delete_record({"name": "John Doe"})

To delete the entire collection:

mongo.drop_collection()

To delete the entire database:

mongo.drop_database()

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License.

Contact

For any questions or suggestions, please contact yuvaneshkm05@gmail.com

Connect

Connect with me on LinkedIn

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

mdb_connect_pkg-1.1.1.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

mdb_connect_pkg-1.1.1-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

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