MongoDB for Pyramid

from pymongo import MongoClient
client = MongoClient('mongodb://localhost:27017/')
db = client.vinlib
a=recall.find({'YEARTXT':'2010'})
a=recall.find({'YEARTXT':'2010'})

mongo_uri = mongodb://localhost:27017/mydata

    db_url = urlparse(settings['mongo_uri'])
    config.registry.db = MongoClient(
       host=db_url.hostname,
       port=db_url.port,
    )
    def add_db(request):
       db = config.registry.db[db_url.path[1:]]
       if db_url.username and db_url.password:
           db.authenticate(db_url.username, db_url.password)
       return db
    config.add_request_method(add_db, 'db', reify=True)

    #db is the database from URI, so in my case i already got mydata database, and what I'm accessing now is collection/table.
    mytable=request.db.recall
    print(mytable.find_one())

MyWiki: Pyramid/mongodb (last edited 2016-10-05 04:30:55 by LukaszSzybalski)