Debugtoolbar for Mongo in Pyramid
This project provides a debugtoolbar for mongodb in pyramid. Keep in mind that this is not compatible with pyramid_mongo.
It supports multiple databases and logs all queries and their explain()
data when enabled.
Setup
pip install pyramid_mongodb2_debugtoolbar
In your app's ini file, have:
[app:main]
mongo_uri = mongodb://username:password@mongodb.host.com:27017/authdb
mongo_dbs =
foo
bar
pyramid.includes =
pyramid_mako
pyramid_debugtoolbar
pyramid_mongodb2
pyramid_mongodb2_debugtoolbar
debugtoolbar.includes =
pyramid_mongodb2_debugtoolbar:MongoToolbar
In your views.py
you can now do:
from pyramid.view import view_config
@view_config(route_name='home', renderer="templates/landing.mako")
def my_view(request):
return {
'some_data': request.db_foo.some_collection.find({'a': {'$gte': 5}}, {'_id': False}),
'other_data': request.db_bar.visitors.insert_one({'person': request.remote_addr}),
}
Any time you access db_foo.callable
, it will be logged in request.query_log
, which can then be shown when you open the debugtoolbar.
Screenshots
Here's what the toolbar looks like in action:
Clicking the database or collection name will take you to the relevant section of the collections tab. Clicking the operation name will take you to its pymongo documentation.
Clicking the explain button will show you the explain()
result for a cursor.
You can view detailed connection information here, clicking the field name will take you to the pymongo documentation for that field.
This page show dbstats
for all connected databases used in this request and their collections.
Here we can see the use of multiple databases in a single project.