{"id":15937038,"url":"https://github.com/jonnoftw/pyramid_mongodb2","last_synced_at":"2025-10-19T14:40:05.543Z","repository":{"id":60722600,"uuid":"142379248","full_name":"JonnoFTW/pyramid_mongodb2","owner":"JonnoFTW","description":"Simple library to integrate mongodb into your pyramid application","archived":false,"fork":false,"pushed_at":"2019-12-28T13:55:55.000Z","size":22,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-08T04:41:50.517Z","etag":null,"topics":["mongodb","pymongo","pyramid"],"latest_commit_sha":null,"homepage":null,"language":"Mako","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JonnoFTW.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-26T02:43:05.000Z","updated_at":"2021-05-14T07:01:01.000Z","dependencies_parsed_at":"2022-10-03T21:19:10.886Z","dependency_job_id":null,"html_url":"https://github.com/JonnoFTW/pyramid_mongodb2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnoFTW%2Fpyramid_mongodb2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnoFTW%2Fpyramid_mongodb2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnoFTW%2Fpyramid_mongodb2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnoFTW%2Fpyramid_mongodb2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JonnoFTW","download_url":"https://codeload.github.com/JonnoFTW/pyramid_mongodb2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222046000,"owners_count":16922023,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mongodb","pymongo","pyramid"],"created_at":"2024-10-07T04:41:49.742Z","updated_at":"2025-10-19T14:40:05.409Z","avatar_url":"https://github.com/JonnoFTW.png","language":"Mako","funding_links":[],"categories":[],"sub_categories":[],"readme":"Pyramid Mongodb\n===============\n\nA simple library to integrate mongodb into your pyramid application. Comes with a debugtoolbar.\n\nFeatures\n--------\n\n* Supports multiple databases\n* Configuration only setup\n* Integrated debugtoolbar with:\n  * Shows db response times\n  * `explain()` for cursor results\n  * Connection information\n  * Database and collection stats\n* Avoids recreating and closing `MongoClient` on every request. \n\nSetup\n-----\n```bash\npip install pyramid_mongodb2\n```\n\nAdd the following to your application's ini file, (include `pyramid_mongodb2:MongoToolbar` in `debugtoolbar.includes` if you want to debug):\n\n```ini\n[app:main]\nmongo_uri = mongodb://username:password@mongodb.host.com:27017/authdb\nmongo_dbs = \n    foo\n    bar\n    baz-quux\n    foo-test = foo\npyramid.includes =\n    pyramid_mako    \n    pyramid_debugtoolbar\n    pyramid_mongodb2\ndebugtoolbar.includes =\n    pyramid_mongodb2:MongoToolbar\n```\nThe code will use `config.add_request_method()` to add a `Database` object to your requests, where each database is accessible by `db_database_name`, as defined in your configuration.\n\n**Note**: database names with hyphens in them will be converted to underscores, that is database `baz-quux` will be accessible by `request.db_baz_quux`. \n\nWhen doing `foo-test = foo`, the mongodb database with name `foo-test` will be assigned to `request.db_foo`. \nThis helps when testing so that you can use a separate database for development, testing and production without\nchanging your application code, or if you just want to alias a database name.\n\n \nIn your code where you can access `request`, you now have the following variables:\n\n```python\nrequest.db\nrequest.db_foo\nrequest.db_bar\nrequest.db_baz_quux\nrequest.db_foo\n```\n`request.db` is the `MongoClient` object, should you ever need it.\n\nIn your view code, you can do this:\n\n```python\nfrom pyramid.view import view_config\n\n@view_config(route_name='home', renderer=\"templates/landing.mako\")\ndef my_view(request):\n    return {\n        'some_data': request.db_foo.some_collection.find({'a': {'$gte': 5}}, {'_id': False}),\n        'other_data': request.db_bar.visitors.insert_one({'person': request.remote_addr}),\n    }\n```\n\nDebugging\n---------\n\nWith debugging enabled, all queries will be logged in `request.query_log`, when the debugtoolbar is opened, you can \nthen view the execution time and `explain()` of cursor results. You can also see connection settings and stats for \ndatabases and collections.\n\nScreenshots\n-----------\n\nHere's what the toolbar looks like in action:\n\nClicking 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.\n![debug1](https://user-images.githubusercontent.com/650314/43239055-06890ce6-90d0-11e8-8761-53460bc65ced.png)\n\nClicking the explain button will show you the `explain()` result for a cursor.\n![debug2](https://user-images.githubusercontent.com/650314/43239051-05e0e8f4-90d0-11e8-93f4-8a4d1c42af14.png)\nYou can view detailed connection information here, clicking the field name will take you to the pymongo documentation for that field.\n![debug3](https://user-images.githubusercontent.com/650314/43239052-06099272-90d0-11e8-8cb0-d51465dd12a2.png)\nThis page show `dbstats` for all connected databases used in this request and their collections.\n![debug4](https://user-images.githubusercontent.com/650314/43239053-063631f6-90d0-11e8-9fc0-9703e4a70464.png)\nHere we can see the use of multiple databases in a single project.\n![debug5](https://user-images.githubusercontent.com/650314/43239054-065f8524-90d0-11e8-9a5a-889e8b23c207.png)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnoftw%2Fpyramid_mongodb2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonnoftw%2Fpyramid_mongodb2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnoftw%2Fpyramid_mongodb2/lists"}