How to use the motor.motor_asyncio.AsyncIOMotorClient function in motor

To help you get started, we’ve selected a few motor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github virtool / virtool / tests / test_setup.py View on Github external
async def test_db(error, mocker, request, spawn_client, test_db_name, mock_setup):
    client = await spawn_client(setup_mode=True)

    actual_host = request.config.getoption("db_host")

    update = {
        "db_host": "foobar" if error == "db_connection_error" else actual_host,
        "db_port": 27017,
        "db_name": test_db_name,
        "db_username": "",
        "db_password": ""
    }

    if error == "db_not_empty_error":
        db_client = motor.motor_asyncio.AsyncIOMotorClient(
            io_loop=client.app.loop,
            host=actual_host,
            port=27017
        )

        await db_client[test_db_name].references.insert_one({"_id": "test"})

    resp = await client.post_form("/setup/db", update)

    assert resp.status == 200

    errors = None

    if error == "db_connection_error":
        errors = dict(mock_setup["errors"], db_connection_error=True)
github avrae / avrae / migrators / character_rewrite / new_character.py View on Github external
print(f"Done migrating {num_chars}/{num_old_chars} characters.")
    if num_chars == num_old_chars:
        print("It's probably safe to drop the collections old_characters and characters_bak now.")

if __name__ == '__main__':
    import asyncio
    import motor.motor_asyncio
    import credentials

    start = time.time()

    if 'mdb' not in sys.argv:
        local_test("temp/characters.json")
    else:
        input("Running full MDB migration. Press enter to continue.")
        mdb = motor.motor_asyncio.AsyncIOMotorClient(credentials.test_mongo_url
                                                     if 'test' in sys.argv else
                                                     "mongodb://localhost:27017").avrae

        asyncio.get_event_loop().run_until_complete(from_db(mdb))

    end = time.time()
    print(f"Done! Took {end - start} seconds.")
github mongodb / motor / doc / examples / aiohttp_example.py View on Github external
def setup_db():
    db = AsyncIOMotorClient().test
    yield from db.pages.drop()
    html = '{}'
    yield from db.pages.insert_one({'_id': 'page-one',
                                    'body': html.format('Hello!')})

    yield from db.pages.insert_one({'_id': 'page-two',
                                    'body': html.format('Goodbye.')})

    return db
# -- setup-end --
github avrae / avrae / migrators / to_mdb / bestiary.py View on Github external
print("Creating compound index on owner|critterdb_id...")
    await mdb.bestiaries.create_index([("owner", pymongo.ASCENDING),
                                       ("critterdb_id", pymongo.ASCENDING)], unique=True)

    print(f"Done! Migrated {num_bestiaries} bestiaries for {num_users} users.")


if __name__ == '__main__':
    from utils.redisIO import RedisIO
    import credentials
    import motor.motor_asyncio
    import asyncio

    rdb = RedisIO(True, credentials.test_redis_url)  # production should run main script
    mdb = motor.motor_asyncio.AsyncIOMotorClient(credentials.test_mongo_url).avrae

    asyncio.get_event_loop().run_until_complete(run(rdb, mdb))
github Python3WebSpider / DouYin / douyin / handlers / mongo.py View on Github external
def __init__(self, conn_uri=None, db='douyin'):
        """
        init save folder
        :param folder:
        """
        super().__init__()
        if not conn_uri:
            conn_uri = 'localhost'
        self.client = AsyncIOMotorClient(conn_uri)
        self.db = self.client[db]
github howie6879 / Sanic-For-Pythoneer / examples / demo05 / aio_mongo / demo.py View on Github external
def client(self, db):
        # motor
        self.motor_uri = 'mongodb://{account}{host}:{port}/{database}'.format(
            account='{username}:{password}@'.format(
                username=self.MONGODB['MONGO_USERNAME'],
                password=self.MONGODB['MONGO_PASSWORD']) if self.MONGODB['MONGO_USERNAME'] else '',
            host=self.MONGODB['MONGO_HOST'] if self.MONGODB['MONGO_HOST'] else 'localhost',
            port=self.MONGODB['MONGO_PORT'] if self.MONGODB['MONGO_PORT'] else 27017,
            database=db)
        return AsyncIOMotorClient(self.motor_uri)
github ErisYoung / douyin_spider / douyin_spider / handler / mongodb.py View on Github external
def __init__(self, con_uri=None, db_name="douyin"):
        """
        init function,you can also enter one mongodb connect_uri
        :param con_uri:
        :param db_name: default name "douyin"
        """
        super().__init__()
        self.con_uri = con_uri or 'localhost'
        self.client = AsyncIOMotorClient(self.con_uri)
        self.db = self.client[db_name]
github avrae / avrae / migrators / to_mdb / all.py View on Github external
from migrators.to_mdb import bestiary, character, combat, lookupsettings, customization
from utils.redisIO import RedisIO


async def run(rdb, mdb):
    await bestiary.run(rdb, mdb)
    await character.run(rdb, mdb)
    await combat.run(rdb, mdb)
    await customization.run(rdb, mdb)
    await lookupsettings.run(rdb, mdb)


if __name__ == '__main__':
    rdb = RedisIO()
    mdb = motor.motor_asyncio.AsyncIOMotorClient("mongodb://localhost:27017").avrae

    asyncio.get_event_loop().run_until_complete(run(rdb, mdb))