Metadata-Version: 2.1
Name: a3mongo
Version: 0.3.0
Summary: a3mongo is a simple wrapper around pymongo to make it easier to use.
Author-email: three-kinds <3179158552@qq.com>
License: MIT
Project-URL: Homepage, https://github.com/three-kinds/a3mongo
Project-URL: Source, https://github.com/three-kinds/a3mongo
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pymongo

# a3mongo

English | [简体中文](README_ZH.md)

`a3mongo` is a simple wrapper around `pymongo` to make it easier to use.

## 1. Introduction

* Multiple MongoDB services can be configured at the same time.
* Some commonly used methods have been encapsulated.

## 2. Usage

### Install

```shell
pip install a3mongo

```

### Examples

```python
CONF = {
    'site_a': {
        "host": "127.0.0.1",
        "port": 27017,
        "username": "username",
        "password": "password",
        "authSource": "site_a",
        "authMechanism": "SCRAM-SHA-256"
    },
    'site_b': {
        "host": "127.0.0.1",
        "port": 27018,
        "username": "username",
        "password": "password",
        "authSource": "site_b",
        "authMechanism": "SCRAM-SHA-256"
    }
}


from a3mongo import MongoClientFactory, MongoTable


class SiteUser(MongoTable):
    table_name = 'site_user'
    db_conf_name = 'site_a'

    
if __name__ == '__main__':
    MongoClientFactory.init_mongo_clients(conf=CONF)
    site_user = SiteUser()
    site_user.create_table()
    site_user.create_index_list(['name', 'gender', 'email'])
    site_user.upsert_many([
        {'name': 'Alice', 'gender': 'female', 'email': 'alice@example.com'},
        {'name': 'Bob', 'gender':'male', 'email': 'bob@example.com'},
        {'name': 'Charlie', 'gender': 'male', 'email': 'charlie@example.com'},
    ])
    male_users = site_user.find({'gender':'male'})

```
