from urllib.parse import urlparse
import pymongo


def includeme(request):
    settings = request.registry.settings
    db_url = urlparse(settings['mongo_uri'])
    connection = pymongo.MongoClient(host=db_url.hostname, port=db_url.port)
    request.registry.mongo_connection = connection


def db_connection(request):
    settings = request.registry.settings
    db_url = urlparse(settings['mongo_uri'])
    db = request.registry.mongo_connection[db_url.path[1:]]
    return db

@@ -150,24 +150,56 @@
 ongo_uri'%5D)%0A
+    settings%5B'db_url'%5D = db_url%0A
     connecti
@@ -344,32 +344,30 @@
 quest):%0A    
-settings
+db_url
  = request.r
@@ -386,53 +386,18 @@
 ings
-%0A    
+%5B'
 db_url
- = urlparse(settings%5B'mongo_uri
 '%5D
-)
 %0A   

move "db_url" to settings