1- var mongodb = require ( "../../lib/mongodb" ) ,
2- request = true ;
3-
4- var db = new mongodb . Db ( 'test_db' , new mongodb . Server ( "127.0.0.1" , 27017 , {
5- auto_reconnect : true
6- } ) , { } ) ;
7-
8- // listen on error
9- db . on ( "error" , function ( err ) {
10- console . log ( 'open request ' , request ) ;
11- console . error ( 'db on error' ) ;
12- console . dir ( err ) ;
13- } ) ;
1+ var mongodb = require ( "../../../lib/mongodb" )
2+ , MongoClient = mongodb . MongoClient
3+ , request = true ;
4+
5+ // var db = new mongodb.Db('test_db', new mongodb.Server("127.0.0.1", 27017, {
6+ // auto_reconnect: true
7+ // }), {});
8+
9+ // // listen on error
10+ // db.on("error", function(err) {
11+ // console.log('open request ', request);
12+ // console.error('db on error');
13+ // console.dir(err);
14+ // });
1415
1516// open connection
16- db . open ( function ( err , client ) {
17+ // db.open(function(err, client) {
18+ MongoClient . connect ( 'mongodb://127.0.0.1:31000/test_db' , function ( err , db ) {
1719if ( err ) {
1820console . error ( err ) ;
1921}
2022
21- var collection = new mongodb . Collection ( client , 'test_collection' ) ;
23+ var collection = db . collection ( 'test_collection' ) ;
2224
2325// define find and modify
2426var findAndModifyLoop = function ( ) {
@@ -27,7 +29,7 @@ db.open(function(err, client) {
2729
2830console . log ( 'findAndModify request (should not be last)' ) ;
2931
30- collection . findAndModify ( { hello : 'world' } , [ [ '_id' , 'asc' ] ] , { $set : { hi : 'there' } } , { w :1 , upsert :true } , function ( err , object ) {
32+ collection . findAndModify ( { hello : 'world' } , [ [ '_id' , 'asc' ] ] , { $set : { hi : 'there' } } , { w :5 , wtimeout : 1000 , upsert :true } , function ( err , object ) {
3133if ( err ) {
3234console . warn ( 'findAndModify error response ' , err . message ) ; // returns error if no matching object found
3335} else {
@@ -38,6 +40,7 @@ db.open(function(err, client) {
3840request = false ;
3941
4042 process . nextTick ( function ( ) {
43+ console . dir ( "number of callbacks :: " + Object . keys ( db . serverConfig . _callBackStore . _notReplied ) . length ) ;
4144 // on result does it again
4245 findAndModifyLoop ( ) ;
4346 } )
@@ -48,14 +51,14 @@ db.open(function(err, client) {
4851findAndModifyLoop ( ) ;
4952} ) ;
5053
51- db . on ( "error" , function ( err ) {
52- console . log ( 'open request ' , request ) ;
53- console . error ( 'db on error' ) ;
54- console . dir ( err ) ;
55- } ) ;
54+ // db.on("error", function(err) {
55+ // console.log('open request ', request);
56+ // console.error('db on error');
57+ // console.dir(err);
58+ // });
5659
57- db . on ( "close" , function ( err ) {
58- console . log ( 'open request ' , request ) ;
59- console . error ( 'db on close' ) ;
60- console . dir ( err ) ;
61- } ) ;
60+ // db.on("close", function(err) {
61+ // console.log('open request ', request);
62+ // console.error('db on close');
63+ // console.dir(err);
64+ // });
0 commit comments