An open API service indexing awesome lists of open source software.

https://github.com/bottlepy/bottle-mongo


https://github.com/bottlepy/bottle-mongo

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

Bottle MongoDB
==============

.. image:: https://travis-ci.org/bottlepy/bottle-mongo.svg?branch=master
:target: https://travis-ci.org/bottlepy/bottle-mongo

This bottle-mongodb plugin integrates MongoDB with your Bottle
application. It injects a MongoDB session in your route and handle the
session cycle.

Support pymongo 3 and 2

Usage Example:

.. code-block:: python

from bottle import Bottle ,redirect
from bottle.ext.mongo import MongoPlugin

from bson.json_util import dumps

app = Bottle()
plugin = MongoPlugin(uri="mongodb://127.0.0.1", db="mydb", json_mongo=True)
app.install(plugin)

@app.route('/', method='GET')
def index(mongodb):
return dumps(mongodb['collection'].find())

@app.route('/create/', method='POST')
def create(mongodb):
mongodb['collection'].insert({'a': 1, 'b': 2})
redirect("/")