Motor (Async MongoDB)

3.7.1 · deprecated · verified Tue Mar 24

DEPRECATED as of May 14, 2025. Motor was the official async Python driver for MongoDB. Superseded by the native AsyncMongoClient in pymongo >= 4.13 (GA). EOL: May 14, 2026. Critical bug fixes only until May 14, 2027. No new features. Current version: 3.7.1. Requires PyMongo 4.9+. For new projects use pymongo's AsyncMongoClient instead.

Warnings

Install

Imports

Quickstart

Async MongoDB using pymongo's native AsyncMongoClient (replaces motor).

# New projects: use pymongo's native async instead of motor
# pip install 'pymongo[srv]'
from pymongo import AsyncMongoClient
import asyncio

async def main():
    client = AsyncMongoClient('mongodb+srv://user:pass@cluster.mongodb.net/')
    db = client['mydb']
    col = db['users']

    # All same methods as sync pymongo but with await
    await col.insert_one({'name': 'Alice', 'age': 30})
    doc = await col.find_one({'name': 'Alice'})
    print(doc)
    await col.update_one({'name': 'Alice'}, {'$set': {'age': 31}})
    count = await col.count_documents({})
    print(count)
    await client.close()

asyncio.run(main())

view raw JSON →