Skip to main content

a simple sanic extension for using motor

Project description

# sanic-mongo


## 特点 Features

+ [motor]( 支持的操作都支持
+ 支持3.5版本以上的

## 依赖 Requirements

1. motor>=1.1
2. pymongo>=3.4.0
3. sanic>=0.4.1

## 安装 Installation

pip install sanic-mongo

## 文档 Document

## 例子 Example

from sanic import Sanic
from sanic.response import json
from sanic_mongo import Mongo

app = Sanic(__name__)
mongo_uri = "mongodb://{host}:{port}/{database}".format(

mongo = Mongo(mongo_uri)
db = mongo(app)
async def get(request):
docs = await db().test_col.find().to_list(length=100)
for doc in docs:
doc['id'] = str(doc['_id'])
del doc['_id']
return json(docs)'/objects')
async def new(request):
doc = request.json
object_id = await db("test_col").save(doc)
return json({'object_id': str(object_id)})

if __name__ == "__main__":'', port=8000)


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sanic-mongo-1.1.0.tar.gz (3.9 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page