On Tue, Feb 26, 2013 at 10:17 PM, Rafael Reuber <[email protected]>wrote:

>
> I want to use MongoDB and I need to make the Mongo data base connection
> available like an single application attribute. I can't follow the tips
> described on pyramid's mongodb cookbook, because there, the mongo connection
> its attached like an request attribute. I need this just because some parts
> of my application haven't an request object and I want to use just one
> connection object to all application code. How can I do this?
>
> Your options are basically:

1) You can use the pyramid.threadlocal.get_current_request to get the
current request object from within your application code.

2) You can implement your own threadlocal as some module level global
somewhere in your code.  See threading.local in Python standard library.

3) Structure your application code to use function signatures that take a
mongodb connection as a parameter, or that take an application context
object of some sort that has access to the mongodb connection.  Or have
your application code inside of classes that are given a mongodb connection
as an attribute, etc...  Basically, some way to get the connection from
view code into whichever other code you're writing.

Chris

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to