This project has moved. For the latest updates, please go here.

Multiple session

Mar 24, 2013 at 12:54 PM
Hi,

From architectural point of view, the way you are initializing connection within base repository class using static class Utils is not the best option, maybe even wrong.

In case of multiple repositories, it will result in multiple independent sessions to MongoDB open on the client side. In general, taking into consideration that it is MongoDB repository, it will work fine having session per repository as you did, however it is much better to share one session over all repository instances.

So I'd suggest rethink the way you are managing sessions in your code.

Whatever you'll decide, it is good work and great initiative to start a project like this one.

Regards,
Alexey
Coordinator
Mar 26, 2013 at 8:11 AM
I will look into it; you do have a point.
Apr 12, 2013 at 8:11 PM
Actually I was wondering the same thing as I see multiple connections to the server from the client. That said I also posted on MongoDB User group and also had a look at http://stackoverflow.com/questions/10241641/what-is-the-right-way-to-manage-mongodb-connections-in-asp-net-mvc and it was said that the C# driver manages a connection pool for you and that way you can create as many instances of the server and database object you want and it would still manage it for you.

Not sure what your thoughts are on this.
Jul 2, 2013 at 12:15 PM
MongoDB driver handles the connection pooling for you. It doesn't matter how many connections or Repositories you create. MongoDB driver will get the same object from pool and returns you. And the default pool size is 5 which is more or less enough.
Coordinator
Jul 3, 2013 at 11:36 AM
tgeek wrote:
MongoDB driver handles the connection pooling for you. It doesn't matter how many connections or Repositories you create. MongoDB driver will get the same object from pool and returns you. And the default pool size is 5 which is more or less enough.
That is true, however:

AlexeyNayda wrote:
From architectural point of view
...and that makes sense in a way. Even if it were only for a "transaction", it would make sense to "group" repositories onto the same connection when possible. Even when the actual connection would be pooled into/onto different underlying (actual) TCP connections to MongoDB, from an architectural POV using the same "virtual" connection would make sense.

However, this is low on my "nice to haves" list and not really a dealbreaker to me.