mongodriver


Namemongodriver JSON
Version 1.3.4 PyPI version JSON
download
home_pagehttps://github.com/jakestrouse00/mongodriver
SummaryObject-oriented interactions with MongoDB
upload_time2024-05-20 20:44:45
maintainerNone
docs_urlNone
authorJake Strouse
requires_python>=3.10
licenseMIT
keywords mongodb
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MongoDriver

An object-oriented package for interacting with MongoDB documents



Features
--------

* Object-oriented
* Update documents without needing to use json
* Use pymongo within the package as well
* Built with type hints
* Removes a lot of [boilerplate](pymongo_vs_mongodriver/README.md) code 
* So simple it works like ✨magic ✨


Quickstart
----------

Install MongoDriver
`python3 -m pip install mongodriver`

```python
from mongodriver import Driver

driver = Driver(
    connection_url="mongodb+srv://example:SecurePassword@testcluster.e2lhq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
    db_name="example_db", collection_name="example_collection")
```
   
Examples
----------
Here is a basic example on how to create a new document and then interact it

```python
from mongodriver import Driver

driver = Driver(
    connection_url="mongodb+srv://example:SecurePassword@testcluster.e2lhq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
    db_name="example_db", collection_name="example_collection")

new_document = driver.create({"foo": 1, "bar": 2})

# print the value of "foo"
print(new_document.foo)  # 1

# change the value of "foo"
new_document.foo = 2
print(new_document.foo)  # 2

# OR

new_document.set({"foo": 2})

# you can also change the value of an attribute with the Driver.Variable.update() method

new_document.foo.update(3)

print(new_document.foo)  # 3
```

Find a document

```python
from mongodriver import Driver

driver = Driver(
    connection_url="mongodb+srv://example:SecurePassword@testcluster.e2lhq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
    db_name="example_db", collection_name="example_collection")

search_query = {"foo": 1}
documents = driver.find(search_query)  # returns a list of documents
# or driver.find_one(search_query) to get only one document
for document in documents:
    print(document)
```

Add more keys into a document

```python
from mongodriver import Driver

driver = Driver(
    connection_url="mongodb+srv://example:SecurePassword@testcluster.e2lhq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
    db_name="example_db", collection_name="example_collection")

json_document = {"foo": 1, "bar": 2}
new_document = driver.create(json_document)

new_document.set({"new_val1": 15, "new_val2": 10})

# OR

new_document.new_val1 = 15
new_document.new_val2 = 10

print(new_document)

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jakestrouse00/mongodriver",
    "name": "mongodriver",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "mongodb",
    "author": "Jake Strouse",
    "author_email": "jstrouse@meh.llc",
    "download_url": "https://files.pythonhosted.org/packages/2d/2b/2eccfed5790bf11cb9f0eb484b659a7ff65fc627a670fb0afb3fb2c1a724/mongodriver-1.3.4.tar.gz",
    "platform": null,
    "description": "# MongoDriver\n\nAn object-oriented package for interacting with MongoDB documents\n\n\n\nFeatures\n--------\n\n* Object-oriented\n* Update documents without needing to use json\n* Use pymongo within the package as well\n* Built with type hints\n* Removes a lot of [boilerplate](pymongo_vs_mongodriver/README.md) code \n* So simple it works like \u2728magic \u2728\n\n\nQuickstart\n----------\n\nInstall MongoDriver\n`python3 -m pip install mongodriver`\n\n```python\nfrom mongodriver import Driver\n\ndriver = Driver(\n    connection_url=\"mongodb+srv://example:SecurePassword@testcluster.e2lhq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority\",\n    db_name=\"example_db\", collection_name=\"example_collection\")\n```\n   \nExamples\n----------\nHere is a basic example on how to create a new document and then interact it\n\n```python\nfrom mongodriver import Driver\n\ndriver = Driver(\n    connection_url=\"mongodb+srv://example:SecurePassword@testcluster.e2lhq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority\",\n    db_name=\"example_db\", collection_name=\"example_collection\")\n\nnew_document = driver.create({\"foo\": 1, \"bar\": 2})\n\n# print the value of \"foo\"\nprint(new_document.foo)  # 1\n\n# change the value of \"foo\"\nnew_document.foo = 2\nprint(new_document.foo)  # 2\n\n# OR\n\nnew_document.set({\"foo\": 2})\n\n# you can also change the value of an attribute with the Driver.Variable.update() method\n\nnew_document.foo.update(3)\n\nprint(new_document.foo)  # 3\n```\n\nFind a document\n\n```python\nfrom mongodriver import Driver\n\ndriver = Driver(\n    connection_url=\"mongodb+srv://example:SecurePassword@testcluster.e2lhq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority\",\n    db_name=\"example_db\", collection_name=\"example_collection\")\n\nsearch_query = {\"foo\": 1}\ndocuments = driver.find(search_query)  # returns a list of documents\n# or driver.find_one(search_query) to get only one document\nfor document in documents:\n    print(document)\n```\n\nAdd more keys into a document\n\n```python\nfrom mongodriver import Driver\n\ndriver = Driver(\n    connection_url=\"mongodb+srv://example:SecurePassword@testcluster.e2lhq.mongodb.net/myFirstDatabase?retryWrites=true&w=majority\",\n    db_name=\"example_db\", collection_name=\"example_collection\")\n\njson_document = {\"foo\": 1, \"bar\": 2}\nnew_document = driver.create(json_document)\n\nnew_document.set({\"new_val1\": 15, \"new_val2\": 10})\n\n# OR\n\nnew_document.new_val1 = 15\nnew_document.new_val2 = 10\n\nprint(new_document)\n\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Object-oriented interactions with MongoDB",
    "version": "1.3.4",
    "project_urls": {
        "Homepage": "https://github.com/jakestrouse00/mongodriver"
    },
    "split_keywords": [
        "mongodb"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a56fae6ec24943159100ae4f4c19fe6bf2257ddafc4632e3cf256eff8be69a50",
                "md5": "3924138120cc1ba2f4eb7b9c1edae299",
                "sha256": "ee68e8ed64695aa79934ee57d6f53830cbceae1ebdc490ca9ec63c1cdeaca70c"
            },
            "downloads": -1,
            "filename": "mongodriver-1.3.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3924138120cc1ba2f4eb7b9c1edae299",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 8160,
            "upload_time": "2024-05-20T20:44:42",
            "upload_time_iso_8601": "2024-05-20T20:44:42.697815Z",
            "url": "https://files.pythonhosted.org/packages/a5/6f/ae6ec24943159100ae4f4c19fe6bf2257ddafc4632e3cf256eff8be69a50/mongodriver-1.3.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2d2b2eccfed5790bf11cb9f0eb484b659a7ff65fc627a670fb0afb3fb2c1a724",
                "md5": "384d41b0132b7054849c7c8f9a79aa11",
                "sha256": "3814090d13aaed2ed61fbc97b77b8b2702e046f78f6844b6243e233d8ddbcb73"
            },
            "downloads": -1,
            "filename": "mongodriver-1.3.4.tar.gz",
            "has_sig": false,
            "md5_digest": "384d41b0132b7054849c7c8f9a79aa11",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 6858,
            "upload_time": "2024-05-20T20:44:45",
            "upload_time_iso_8601": "2024-05-20T20:44:45.148670Z",
            "url": "https://files.pythonhosted.org/packages/2d/2b/2eccfed5790bf11cb9f0eb484b659a7ff65fc627a670fb0afb3fb2c1a724/mongodriver-1.3.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-20 20:44:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jakestrouse00",
    "github_project": "mongodriver",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mongodriver"
}
        
Elapsed time: 4.49767s