Https://github.com/no7dw/mongodb-example
This is the most basic connection query. (Branch Master)
var mongoclient = require (' MongoDB '). Mongoclient , assert = require (' assert ');//Connection Urlvar url = ' Mongodb://localhost:27017/demo '; var findaddr = f Unction (DB, callback) { //Get the Addr collection var collection = db.collection (' addr '); Find some addr collection.find ({}). ToArray (function (err, docs) { callback (err, Docs), }); Use Connect method to connect to the Servermongoclient.connect (URL, function (err, db) { assert.equal (null, err);
console.log ("Connected correctly to Server"); FINDADDR (Db,function (err, docs) { if (err) console.log (' We get err ', err); else console.log (' Result: ', docs); Db.close (); });
Notice the log:
2014-11-20t22:15:52.348+0800 [Initandlisten] connection accepted from 127.0.0.1:50076 #39 (1 connection now OPEN)
2014-11-20t22:15:52.384+0800 [conn39] End connection 127.0.0.1:50076 (0 connections now OPEN)
2014-11-20t22:15:52.425+0800 [Initandlisten] connection accepted from 127.0.0.1:50077 #40 (1 connection now OPEN)
2014-11-20t22:15:52.426+0800 [Initandlisten] connection accepted from 127.0.0.1:50078 #41 (2 connections now OPEN)
2014-11-20t22:15:52.426+0800 [Initandlisten] connection accepted from 127.0.0.1:50079 #42 (3 connections now OPEN)
2014-11-20t22:15:52.427+0800 [Initandlisten] connection accepted from 127.0.0.1:50080 #43 (4 connections now OPEN)
2014-11-20t22:15:52.428+0800 [Initandlisten] connection accepted from 127.0.0.1:50081 #44 (5 connections now OPEN)
2014-11-20t22:15:52.455+0800 [conn40] End Connection 127.0.0.1:50077 (4 connections now OPEN)
2014-11-20t22:15:52.455+0800 [conn41] End Connection 127.0.0.1:50078 (3 connections now OPEN)
2014-11-20t22:15:52.455+0800 [conn42] End Connection 127.0.0.1:50079 (2 connections now OPEN)
2014-11-20t22:15:52.456+0800 [conn43] End Connection 127.0.0.1:50080 (1 connection now OPEN)
2014-11-20t22:15:52.456+0800 [conn44] End connection 127.0.0.1:50081 (0 connections now OPEN)
Reason:
Default MongoDB uses connection poolsize =5 settings
So put him on business to set the size. (Branch less-connection)
var options = { db: {native_parser:true}, server: {poolsize:1}}//Use Connect method to connect to the Serve Rmongoclient.connect (URL, options, function (err, db) { assert.equal (null, err); Console.log ("Connected correctly to Server"); FINDADDR (Db,function (err, docs) { if (err) console.log (' We get err ', err); else console.log (' Result: ', docs); Db.close (); });
Now see MONGD log:
2014-11-20t22:21:46.243+0800 [Initandlisten] connection accepted from 127.0.0.1:50157 #45 (1 connection now OPEN) 2014-11 -20t22:21:46.255+0800 [Conn45] End connection 127.0.0.1:50157 (0 connections now OPEN) 2014-11-20t22:21:46.266+0800 [ Initandlisten] Connection accepted from 127.0.0.1:50158 #46 (1 connection now OPEN) 2014-11-20t22:21:46.278+0800 [conn46] End Connection 127.0.0.1:50158 (0 connections now OPEN)
Seems good. However, such settings can not be adjusted according to business pressure, even have maxpoolsize, Minpoolsize:
- URI. maxpoolsize¶
-
The maximum number of connections in the connection pool. The default value is .
- URI. minpoolsize
-
The minimum number of connections in the connection pool. The default value is 0.
---answer is:
generic-pool
Observations from the simple MongoDB example