Skip to main content

MongoSimplify is a versatile Python library for easy and efficient MongoDB interaction.

Project description

MongoDB Model Library for Python

MongoSimplify is a simple yet powerful library designed for seamless interaction with MongoDB using Python. It provides an intuitive interface for performing common MongoDB operations, making it easy to execute CRUD operations and more. This library is highly versatile and can be integrated into any Python framework, such as Django or Flask, allowing developers to efficiently manage MongoDB interactions with minimal effort.

Table of Contents

Installation

You can install the library via pip. Ensure you have MongoDB and pymongo installed in your Python environment.

pip install MongoSimplify

Usage

Connecting to the Database To use the library, define a subclass of Model to specify your database connection details.

from MongoSimplify.models import models

# setting up host port and database
class Model(Model):
    host = 'localhost'  # or your MongoDB server IP
    port = 27017
    database = 'my_database'

class Product(Mydb): # collection name
    pass

CRUD Operations

Create a Document

# Create a new document
my_doc = {'name': 'Alice', 'age': 30}
new_id = Product.create(my_doc)
print(f"Document created with ID: {new_id}")

Retrieve a Document

# Get a single document
doc = Product.get({'name': 'Alice'})
print(doc)

Update a Document

# Update the document
updated_doc = Product.update({'name': 'Alice'}, {'age': 31})
print(f"Updated documents: {updated_doc.modified_count}")

Delete a Document

# Delete a document
deleted_doc = Prsoduct.delete({'name': 'Alice'})
print(f"Deleted documents: {deleted_doc.deleted_count}")
Additional Operations

Count Documents

# Count documents
count = Product.count()
print(f"Total documents: {count}")

Find Multiple Documents

# Find documents with a limit
docs = Product.find(limit=5)
for doc in docs:
    print(doc)

Bulk Write Operations

# Perform bulk operations
operations = [
    InsertOne({'name': 'Bob', 'age': 25}),
    UpdateOne({'name': 'Alice'}, {'$set': {'age': 32}}),
    DeleteOne({'name': 'Charlie'})
]
result = Product.bulk_write(operations)
print(f"Bulk operation result: {result.bulk_api_result}")

Create Indexes

# Create an index on a field
index_name = Product.create_index([('name', 1)])  # 1 for ascending
print(f"Index created: {index_name}")

Contributing

Contributions to MongoSimplify are welcome! Whether you're fixing bugs, improving documentation, or adding new features, your help is greatly appreciated.

License

This library is licensed under the MIT License. See the LICENSE file for more details.

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

mongosimplify-0.5.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

MongoSimplify-0.5.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file mongosimplify-0.5.0.tar.gz.

File metadata

  • Download URL: mongosimplify-0.5.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for mongosimplify-0.5.0.tar.gz
Algorithm Hash digest
SHA256 b05eacda4ae2ac0bac1b8215b1b7c48258e3d2eac33161082d4ff770ef87cc3a
MD5 76f1bd7e82a4b983bf6790c578c5cddf
BLAKE2b-256 7f6013b5ef27318ccba61b53d33a60f7dfa382bd7ae6cd96c8f8c85ad9ec1aa7

See more details on using hashes here.

File details

Details for the file MongoSimplify-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for MongoSimplify-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54db505906850e7ced2ab738cc06859f2ec68962f7657fae0292bd8274a985dd
MD5 e1b0454dfd3b3d748705996b550145f8
BLAKE2b-256 3cd0a67963f45677979b42e51814dfa09f4ceca45f484e5709765e9023654256

See more details on using hashes here.

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