{"id":21215296,"url":"https://github.com/romis2012/mongojet","last_synced_at":"2026-02-22T14:25:18.728Z","repository":{"id":236904094,"uuid":"793388161","full_name":"romis2012/mongojet","owner":"romis2012","description":"Asynchronous (asyncio) MongoDB client for Python","archived":false,"fork":false,"pushed_at":"2026-02-14T14:21:32.000Z","size":1441,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-02-14T22:35:01.313Z","etag":null,"topics":["asyncio","database-driver","mongodb","python","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/romis2012.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-04-29T06:10:08.000Z","updated_at":"2026-02-14T14:16:24.000Z","dependencies_parsed_at":"2024-05-10T06:40:45.359Z","dependency_job_id":"1fd626bf-39e8-4644-9846-23184e056976","html_url":"https://github.com/romis2012/mongojet","commit_stats":null,"previous_names":["romis2012/mongojet"],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/romis2012/mongojet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romis2012%2Fmongojet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romis2012%2Fmongojet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romis2012%2Fmongojet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romis2012%2Fmongojet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romis2012","download_url":"https://codeload.github.com/romis2012/mongojet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romis2012%2Fmongojet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29604175,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T04:38:07.383Z","status":"ssl_error","status_checked_at":"2026-02-19T04:35:50.016Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncio","database-driver","mongodb","python","rust"],"created_at":"2024-11-20T21:36:42.313Z","updated_at":"2026-02-19T05:03:54.137Z","avatar_url":"https://github.com/romis2012.png","language":"Rust","readme":"### Mongojet\n\n[![CI](https://github.com/romis2012/mongojet/actions/workflows/python-ci.yml/badge.svg)](https://github.com/romis2012/mongojet/actions/workflows/python-ci.yml)\n[![Coverage Status](https://codecov.io/gh/romis2012/mongojet/branch/master/graph/badge.svg)](https://codecov.io/gh/romis2012/mongojet)\n[![PyPI version](https://badge.fury.io/py/mongojet.svg)](https://pypi.python.org/pypi/mongojet)\n[![versions](https://img.shields.io/pypi/pyversions/mongojet.svg)](https://github.com/romis2012/mongojet)\n\nAsync (asyncio) MongoDB client for Python. \nIt uses [Rust MongoDB driver](https://github.com/mongodb/mongo-rust-driver) and [tokio](https://github.com/tokio-rs/tokio) under the hood.\nMongojet is 2-4x faster than Motor (and 1.5-3.5x faster than PyMongo AsyncMongoClient) in high concurrency scenarios (see benchmarks below).\n\n## Requirements\n- Python \u003e= 3.9\n- pymongo\u003e=4.6.2 (only `bson` package is required)\n\n\n## Installation\n```\npip install mongojet\n```\n\n## Usage\n\nMongojet has an API similar to PyMongo/Motor (but not exactly the same)\n\n### Creating a Client\nTypically, you should create a single instance of Client per application/process.\nAll client options should be passed via [MongoDB connection string](https://www.mongodb.com/docs/manual/reference/connection-string/).\n```python\nfrom mongojet import create_client, ReadPreference\n\nclient = await create_client('mongodb://localhost:27017/test_database?maxPoolSize=16')\n```\n\n### Getting a Database\ndefault database\n```python\ndb = client.get_default_database()\n```\ndatabase with specific name\n```python\ndb = client.get_database('test_database')\n```\ndatabase with specific name and options\n```python\ndb = client.get_database('test_database', read_preference=ReadPreference(mode='secondaryPreferred'))\n```\n\n### Getting a Collection\n```python\ncollection = db['test_collection']\n```\nwith options\n```python\ncollection = db.get_collection('test_collection', read_preference=ReadPreference(mode='secondary'))\n```\n\n### Inserting documents\n`insert_one`\n```python\ndocument = {'key': 'value'}\nresult = await collection.insert_one(document)\nprint(result)\n#\u003e {'inserted_id': ObjectId('...')}\n```\n`insert_many`\n```python\ndocuments = [{'i': i} for i in range(1000)]\nresult = await collection.insert_many(documents)\nprint(len(result['inserted_ids']))\n#\u003e 1000\n```\n### Find documents\n\n`find_one` (to get a single document)\n```python\ndocument = await collection.find_one({'i': 1})\nprint(document)\n#\u003e {'_id': ObjectId('...'), 'i': 1}\n```\n\n`find` (to get cursor which is an async iterator)\n```python\ncursor = await collection.find({'i': {'$gt': 5}}, sort={'i': -1}, limit=10)\n```\nyou can iterate over the cursor using the `async for` loop\n```python\nasync for document in cursor:\n    print(document)\n```\nor collect cursor to list of documents using `to_list` method\n```python\ndocuments = await cursor.to_list()\n```\n\n`find_many` (to get list of documents in single batch)\n```python\ndocuments = await collection.find_many({'i': {'$gt': 5}}, sort={'i': -1}, limit=10)\n```\n\n### Counting documents\n```python\nn = await collection.count_documents({'i': {'$gte': 500}})\nprint(n)\n#\u003e 500\n```\n\n### Aggregating documents\n```python\ncursor = await collection.aggregate(pipeline=[\n    {'$match': {'i': {'$gte': 10}}},\n    {'$sort': {'i': 1}},\n    {'$limit': 10},\n])\ndocuments = await cursor.to_list()\nprint(documents)\n```\n\n### Updating documents\n\n`replace_one`\n```python\nresult = await collection.replace_one(filter={'i': 5}, replacement={'i': 5000})\nprint(result)\n#\u003e {'matched_count': 1, 'modified_count': 1, 'upserted_id': None}\n```\n\n`update_one`\n```python\nresult = await collection.update_one(filter={'i': 5}, update={'$set': {'i': 5000}}, upsert=True)\nprint(result)\n#\u003e {'matched_count': 0, 'modified_count': 0, 'upserted_id': ObjectId('...')}\n```\n\n`update_many`\n```python\nresult = await collection.update_many(filter={'i': {'$gte': 100}}, update={'$set': {'i': 0}})\nprint(result)\n#\u003e {'matched_count': 900, 'modified_count': 900, 'upserted_id': None}\n```\n\n### Deleting documents\n`delete_one`\n```python\nresult = await collection.delete_one(filter={'i': 5})\nprint(result)\n#\u003e {'deleted_count': 1}\n```\n`delete_many`\n```python\nresult = await collection.delete_many(filter={'i': {'$gt': 5}})\nprint(result)\n#\u003e {'deleted_count': 94}\n```\n\n### Working with GridFS\n```python\nbucket = db.gridfs_bucket(bucket_name=\"images\")\n\nwith open('/path/to/my/awesome/image.png', mode='rb') as file:\n    data = file.read()\n    result = await bucket.put(data, filename='image.png', content_type='image/png')\n    file_id = result['file_id']\n\nwith open('/path/to/my/awesome/image_copy.png', mode='wb') as file:\n    data = await bucket.get_by_id(file_id)\n    file.write(data)\n\nawait bucket.delete(file_id)\n```\n\n## Simple benchmark (lower is better):\n### find_one\n\u003c!-- ![find_one](./benchmarks/find_one.png) --\u003e\n![find_one](https://github.com/romis2012/mongojet/blob/master/benchmarks/find_one.png?raw=true)\n### insert_one\n![insert_one](https://github.com/romis2012/mongojet/blob/master/benchmarks/insert.png?raw=true)\n### iterate over cursor\n![cursor](https://github.com/romis2012/mongojet/blob/master/benchmarks/cursor.png?raw=true)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromis2012%2Fmongojet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromis2012%2Fmongojet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromis2012%2Fmongojet/lists"}