Skip to content

Does runtime persistence options thread safed? #5770

Answered by jamis
midnight-wonderer asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @midnight-wonderer! The persistence options are thread safe; they ultimately call PersistenceContext#get_context (here), which fetches the information from thread-local storage.

By "non-default" clients, do you mean clients created ad-hoc, instead of declared in the mongoid config? The client option requires a client name, but you can declare a new client and assign it a name programmatically, like so:

Mongoid::Clients.set(:client_name, client_instance)

In general, we encourage developers to use previously-declared clients for this, rather than ad-hoc clients. Use of ad-hoc clients can make it difficult to understand what the behavior of a particular query or update really is.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by midnight-wonderer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants