MongoDB2.6 's Cxx driver (Mongo-cxx-driver-26compat), built-in with a database connection pool, makes it easy to manage database connections, but official documentation is obscure and novice beginners often don't know how to use connection pooling to get a database connection. This article briefly describes how to use a basic connection pool.
The first thing to make clear is that although there is a connection pool class, there is no need to display the class to be called, using the following method:
Mongo::scopeddbconnection scopedconn = mongo::scopeddbconnection (dbhost); MONGO::D bclientbase* conn = ScopedConn.get ( );
The code is interpreted as follows, the first line uses the Mongo::scopeddbconnection object, which is responsible for getting a specified database connection from the built-in database connection pool, Dbhost represents the database address, and the native test is "127.0.0.1:27017". Then from the linked object can get the specific database connection operation object Pointer Dbclientbase, for Insert,remove,update,query,findone and other operations.
Note When you are finished using the connection, you need to call the following code to release the link, otherwise the connection will never be released causing the problem of creating a new connection:
Scopedconn.done ();
In general, the use of MongoDB connection pool is very simple, if the official has a practical example to tell users how to use will be better understand
This work is licensed under the Creative Commons Attribution-NonCommercial use-Share 4.0 International license agreement in the same way.