-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best practice #76
Comments
Can you please provide guidance (since you are the only authority on the matter) on how and when to use |
This is a copy of: https://github.com/go-mgo/mgo/issues/287 which the original author did not answer. Since the original author has now retired, I guess you are the highest power. It would be great if a higher power answered it because I noticed there are 100's of people asking the same question on forums and many are linking to my original issue. Thank you for your time. |
Does this package do connection pooling similar to |
Hi @pjebs You're not the first to ask this! I'd suggest using You could use Calling Dial each time involves opening a connection, performing any authentication (not cheap) and then closing it when you're done, having to do it all again for the next request - this is a lot of round trips and very expensive for both the client and server - you should avoid this method. I've added an example to the documentation - this should make it into the master branch / godoc.org soon. I hope this helps, does it answer all your questions? Dom |
thank you. |
I notice there is a
session, err := mgo.Dial(MONGODB_DIAL_URL)
function and alsoClone
andCopy
.If we are using MongoDB for a web app backend, I'm wondering what the best practice is out of these options.
Call Dial when we need to access database and close as soon as possible (usually with defer within same function).
Call Dial at start of request and close at end of request cycle after servicing request.
that request.
(Obviously For option 2, an improvement is to dial lazily but that's obvious to readers).
Assuming that we may need to do multiple database queries per request, how exactly do we use
clone
and/orcopy
?The text was updated successfully, but these errors were encountered: