.NET best practices for MongoDB connections?

前端 未结 6 970
臣服心动
臣服心动 2020-12-12 14:40

I\'ve been playing with MongoDB recently (It\'s AMAZINGLY FAST) using the C# driver on GitHub. Everything is working just fine in my little single threaded console app that

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 15:03

    Connection Pool should be your answer.

    The feature is being developed (please see http://jira.mongodb.org/browse/CSHARP-9 for more detail).

    Right now, for web application, the best practice is to connect at the BeginRequest and release the connection at EndRequest. But to me, I think that operation is too expensive for each request without Connection Pool. So I decide to have the global Mongo object and using that as shared resource for every threads (If you get the latest C# driver from github right now, they also improve the performance for concurrency a bit).

    I don't know the disadvantage for using Global Mongo object. So let's wait for another expert to comment on this.

    But I think I can live with it until the feature(Connection pool) have been completed.

提交回复
热议问题