MongoSimplify


NameMongoSimplify JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://github.com/mukit-hasan/MongoSimplify
SummaryMongoSimplify is a versatile Python library for easy and efficient MongoDB interaction.
upload_time2024-09-25 06:46:38
maintainerNone
docs_urlNone
authorMukit Hasan
requires_python>=3.11
licenseNone
keywords python pymongo mongosimplify mongodb nosql
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](#installation)
- [Usage](#usage)
  - [Connecting to the Database](#connecting-to-the-database)
  - [CRUD Operations](#crud-operations)
  - [Additional Operations](#additional-operations)
- [Examples](#examples)
- [License](#license)

## Installation

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

```bash
pip install MongoSimplify
```


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

```py
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
```py
# 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
```python
# Get a single document
doc = Product.get({'name': 'Alice'})
print(doc)
```

## Update a Document

```python
# Update the document
updated_doc = Product.update({'name': 'Alice'}, {'age': 31})
print(f"Updated documents: {updated_doc.modified_count}")
```
## Delete a Document
```python
# Delete a document
deleted_doc = Prsoduct.delete({'name': 'Alice'})
print(f"Deleted documents: {deleted_doc.deleted_count}")
Additional Operations
```
## Count Documents
```python
# Count documents
count = Product.count()
print(f"Total documents: {count}")
```
## Find Multiple Documents
```python
# Find documents with a limit
docs = Product.find(limit=5)
for doc in docs:
    print(doc)
```

## Bulk Write Operations

```python
# 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
```python
# 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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mukit-hasan/MongoSimplify",
    "name": "MongoSimplify",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "python, pymongo, MongoSimplify, mongodb, nosql",
    "author": "Mukit Hasan",
    "author_email": "mukithasan58@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7f/60/13b5ef27318ccba61b53d33a60f7dfa382bd7ae6cd96c8f8c85ad9ec1aa7/mongosimplify-0.5.0.tar.gz",
    "platform": null,
    "description": "# MongoDB Model Library for Python\r\n\r\nMongoSimplify 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.\r\n\r\n## Table of Contents\r\n\r\n- [Installation](#installation)\r\n- [Usage](#usage)\r\n  - [Connecting to the Database](#connecting-to-the-database)\r\n  - [CRUD Operations](#crud-operations)\r\n  - [Additional Operations](#additional-operations)\r\n- [Examples](#examples)\r\n- [License](#license)\r\n\r\n## Installation\r\n\r\nYou can install the library via pip. Ensure you have MongoDB and pymongo installed in your Python environment.\r\n\r\n```bash\r\npip install MongoSimplify\r\n```\r\n\r\n\r\n# Usage\r\nConnecting to the Database\r\nTo use the library, define a subclass of Model to specify your database connection details.\r\n\r\n```py\r\nfrom MongoSimplify.models import models\r\n\r\n# setting up host port and database\r\nclass Model(Model):\r\n    host = 'localhost'  # or your MongoDB server IP\r\n    port = 27017\r\n    database = 'my_database'\r\n\r\nclass Product(Mydb): # collection name\r\n    pass\r\n\r\n```\r\n\r\n# CRUD Operations\r\n## Create a Document\r\n```py\r\n# Create a new document\r\nmy_doc = {'name': 'Alice', 'age': 30}\r\nnew_id = Product.create(my_doc)\r\nprint(f\"Document created with ID: {new_id}\")\r\n```\r\n## Retrieve a Document\r\n```python\r\n# Get a single document\r\ndoc = Product.get({'name': 'Alice'})\r\nprint(doc)\r\n```\r\n\r\n## Update a Document\r\n\r\n```python\r\n# Update the document\r\nupdated_doc = Product.update({'name': 'Alice'}, {'age': 31})\r\nprint(f\"Updated documents: {updated_doc.modified_count}\")\r\n```\r\n## Delete a Document\r\n```python\r\n# Delete a document\r\ndeleted_doc = Prsoduct.delete({'name': 'Alice'})\r\nprint(f\"Deleted documents: {deleted_doc.deleted_count}\")\r\nAdditional Operations\r\n```\r\n## Count Documents\r\n```python\r\n# Count documents\r\ncount = Product.count()\r\nprint(f\"Total documents: {count}\")\r\n```\r\n## Find Multiple Documents\r\n```python\r\n# Find documents with a limit\r\ndocs = Product.find(limit=5)\r\nfor doc in docs:\r\n    print(doc)\r\n```\r\n\r\n## Bulk Write Operations\r\n\r\n```python\r\n# Perform bulk operations\r\noperations = [\r\n    InsertOne({'name': 'Bob', 'age': 25}),\r\n    UpdateOne({'name': 'Alice'}, {'$set': {'age': 32}}),\r\n    DeleteOne({'name': 'Charlie'})\r\n]\r\nresult = Product.bulk_write(operations)\r\nprint(f\"Bulk operation result: {result.bulk_api_result}\")\r\n```\r\n\r\n## Create Indexes\r\n```python\r\n# Create an index on a field\r\nindex_name = Product.create_index([('name', 1)])  # 1 for ascending\r\nprint(f\"Index created: {index_name}\")\r\n```\r\n\r\n# Contributing\r\nContributions to MongoSimplify are welcome! Whether you're fixing bugs, improving documentation, or adding new features, your help is greatly appreciated. \r\n\r\n# License\r\nThis library is licensed under the MIT License. See the LICENSE file for more details.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "MongoSimplify is a versatile Python library for easy and efficient MongoDB interaction.",
    "version": "0.5.0",
    "project_urls": {
        "Homepage": "https://github.com/mukit-hasan/MongoSimplify"
    },
    "split_keywords": [
        "python",
        " pymongo",
        " mongosimplify",
        " mongodb",
        " nosql"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3cd0a67963f45677979b42e51814dfa09f4ceca45f484e5709765e9023654256",
                "md5": "e1b0454dfd3b3d748705996b550145f8",
                "sha256": "54db505906850e7ced2ab738cc06859f2ec68962f7657fae0292bd8274a985dd"
            },
            "downloads": -1,
            "filename": "MongoSimplify-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e1b0454dfd3b3d748705996b550145f8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 5125,
            "upload_time": "2024-09-25T06:46:36",
            "upload_time_iso_8601": "2024-09-25T06:46:36.690689Z",
            "url": "https://files.pythonhosted.org/packages/3c/d0/a67963f45677979b42e51814dfa09f4ceca45f484e5709765e9023654256/MongoSimplify-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f6013b5ef27318ccba61b53d33a60f7dfa382bd7ae6cd96c8f8c85ad9ec1aa7",
                "md5": "76f1bd7e82a4b983bf6790c578c5cddf",
                "sha256": "b05eacda4ae2ac0bac1b8215b1b7c48258e3d2eac33161082d4ff770ef87cc3a"
            },
            "downloads": -1,
            "filename": "mongosimplify-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "76f1bd7e82a4b983bf6790c578c5cddf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 4763,
            "upload_time": "2024-09-25T06:46:38",
            "upload_time_iso_8601": "2024-09-25T06:46:38.400468Z",
            "url": "https://files.pythonhosted.org/packages/7f/60/13b5ef27318ccba61b53d33a60f7dfa382bd7ae6cd96c8f8c85ad9ec1aa7/mongosimplify-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-25 06:46:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mukit-hasan",
    "github_project": "MongoSimplify",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mongosimplify"
}
        
Elapsed time: 0.75935s