==========
nmongo
==========
Azure Cosmos DB for MongoDB client for CPython and MicroPython.
It has mongo shell like APIs.
Support platform
------------------
- CPython 3.11+ https://www.python.org
- MicroPython
Install
----------
CPython
::
$ python3 -m pip install nmongo
MicroPython
Go interactive shell and install with mip as follow.
::
>>> import mip
>>> mip.install("datetime")
>>> mip.install(""https://github.com/nakagami/nmongo/blob/master/nmongo.py"")
Example
-----------
Connect to Azure CosmosDB
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::
>>> import nmongo
>>> db = nmongo.connect('xxx.mongo.cosmos.azure.com', 'somewhatdatabase', user='xxx', password='password', port=10255, use_ssl=True)
>>>
Create
~~~~~~~
::
>>> db.fruits.insert({'name': 'apple', 'price': 200})
1
>>> db.fruits.insert([{'name': 'orange', 'price': 100}, {'name': 'banana', 'price': 50}])
2
>>> db.fruits.count()
3
>>>
Read
~~~~~~~
::
>>> cur = db.fruits.find({'name': 'banana'})
>>> cur.fetchone()
{'price': 50, '_id': ObjectId("5826b2313d28909ce9f6ea63"), 'name': 'banana'}
>>> cur = db.fruits.find()
>>> cur.fetchall()
[{'price': 200, '_id': ObjectId("5826b2273d28909ce9f6ea61"), 'name': 'apple'}, {'price': 100, '_id': ObjectId("5826b2313d28909ce9f6ea62"), 'name': 'orange'}, {'price': 50, '_id': ObjectId("5826b2313d28909ce9f6ea63"), 'name': 'banana'}]
>>>
Update
~~~~~~~
::
>>> db.fruits.update({'name': 'banana'}, {'$inc': {'price': 20}})
{'nModified': 1, 'ok': 1, 'n': 1}
>>> cur = db.fruits.find({'name': 'banana'})
>>> cur.fetchone()
{'_id': ObjectId("5823dd6d3d28909ce9f6e99c"), 'name': 'banana', 'price': 70}
>>>
Delete
~~~~~~~
::
>>> db.fruits.remove({'name': 'banana'})
1
>>> db.fruits.count()
2
Count each collection records
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::
>>> for collection in db.getCollections():
... print(collection.name, collection.count())
...
fruits 3
>>> db.getCollection('fruits').count()
3
>>>
This driver uses OP_COMMNAD OP_COMMANDREPLY, which was added in MongoDB3.2 and removed in MongoDB 4.2.
These documents have been removed too from the official documentation. Please let me know if there is any good documentation left somewhere.
Features Not Implemented
--------------------------
- GridFS
Raw data
{
"_id": null,
"home_page": "https://github.com/nakagami/nmongo/",
"name": "nmongo",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "MongoDB",
"author": "Hajime Nakagami",
"author_email": "nakagami@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/49/44/8c2d1569ef367f3ab97fb1b5ef65f4345cf5f646fd28dd53383031bf7af3/nmongo-0.6.0.tar.gz",
"platform": null,
"description": "==========\nnmongo\n==========\n\nAzure Cosmos DB for MongoDB client for CPython and MicroPython.\n\nIt has mongo shell like APIs.\n\nSupport platform\n------------------\n\n- CPython 3.11+ https://www.python.org\n- MicroPython\n\nInstall\n----------\n\nCPython\n\n::\n\n $ python3 -m pip install nmongo\n\n\nMicroPython\n\nGo interactive shell and install with mip as follow.\n\n::\n\n >>> import mip\n >>> mip.install(\"datetime\")\n >>> mip.install(\"\"https://github.com/nakagami/nmongo/blob/master/nmongo.py\"\")\n\nExample\n-----------\n\n\nConnect to Azure CosmosDB\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\n::\n\n >>> import nmongo\n >>> db = nmongo.connect('xxx.mongo.cosmos.azure.com', 'somewhatdatabase', user='xxx', password='password', port=10255, use_ssl=True)\n >>>\n\n\nCreate\n~~~~~~~\n\n::\n\n >>> db.fruits.insert({'name': 'apple', 'price': 200})\n 1\n >>> db.fruits.insert([{'name': 'orange', 'price': 100}, {'name': 'banana', 'price': 50}])\n 2\n >>> db.fruits.count()\n 3\n >>>\n\nRead\n~~~~~~~\n\n::\n\n >>> cur = db.fruits.find({'name': 'banana'})\n >>> cur.fetchone()\n {'price': 50, '_id': ObjectId(\"5826b2313d28909ce9f6ea63\"), 'name': 'banana'}\n >>> cur = db.fruits.find()\n >>> cur.fetchall()\n [{'price': 200, '_id': ObjectId(\"5826b2273d28909ce9f6ea61\"), 'name': 'apple'}, {'price': 100, '_id': ObjectId(\"5826b2313d28909ce9f6ea62\"), 'name': 'orange'}, {'price': 50, '_id': ObjectId(\"5826b2313d28909ce9f6ea63\"), 'name': 'banana'}]\n >>>\n\nUpdate\n~~~~~~~\n\n::\n\n >>> db.fruits.update({'name': 'banana'}, {'$inc': {'price': 20}})\n {'nModified': 1, 'ok': 1, 'n': 1}\n >>> cur = db.fruits.find({'name': 'banana'})\n >>> cur.fetchone()\n {'_id': ObjectId(\"5823dd6d3d28909ce9f6e99c\"), 'name': 'banana', 'price': 70}\n >>>\n\n\nDelete\n~~~~~~~\n\n::\n\n >>> db.fruits.remove({'name': 'banana'})\n 1\n >>> db.fruits.count()\n 2\n\nCount each collection records\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n::\n\n >>> for collection in db.getCollections():\n ... print(collection.name, collection.count())\n ...\n fruits 3\n >>> db.getCollection('fruits').count()\n 3\n >>>\n\nThis driver uses OP_COMMNAD OP_COMMANDREPLY, which was added in MongoDB3.2 and removed in MongoDB 4.2.\nThese documents have been removed too from the official documentation. Please let me know if there is any good documentation left somewhere.\n\nFeatures Not Implemented\n--------------------------\n\n- GridFS\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Azure Cosmos DB for MongoDB client",
"version": "0.6.0",
"project_urls": {
"Homepage": "https://github.com/nakagami/nmongo/"
},
"split_keywords": [
"mongodb"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "49448c2d1569ef367f3ab97fb1b5ef65f4345cf5f646fd28dd53383031bf7af3",
"md5": "3fd941dc40cf5bb549a0a9692d57882c",
"sha256": "7f0f8764dd5809c23c617db0bb29f47c087e3e74d74099064e8e643157e1da42"
},
"downloads": -1,
"filename": "nmongo-0.6.0.tar.gz",
"has_sig": false,
"md5_digest": "3fd941dc40cf5bb549a0a9692d57882c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11991,
"upload_time": "2025-02-07T02:30:03",
"upload_time_iso_8601": "2025-02-07T02:30:03.082538Z",
"url": "https://files.pythonhosted.org/packages/49/44/8c2d1569ef367f3ab97fb1b5ef65f4345cf5f646fd28dd53383031bf7af3/nmongo-0.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-07 02:30:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nakagami",
"github_project": "nmongo",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "nmongo"
}