@@ -60,26 +60,26 @@ var tests = testCase({
6060 client . on ( "error" , function ( err ) {
6161 numberOfFailsCounter = numberOfFailsCounter + 1 ;
6262 } ) ;
63-
63+
6464 process . on ( 'uncaughtException' , exceptionHandler )
65-
65+
6666 client . createCollection ( 'error_test' , function ( err , collection ) {
67-
67+
6868 var testObject = { } ;
6969 for ( var i = 0 ; i < 5000 ; i ++ ) {
7070 testObject [ 'setting_' + i ] = i ;
7171 }
72-
72+
7373 testObject . name = 'test1' ;
7474 var c = 0 ;
75-
75+
7676 var counter = 0 ;
7777 collection . insert ( [ testObject , { name :'test2' } ] , { safe :true } , function ( err , doc ) {
7878 var findOne = function ( ) {
7979 collection . findOne ( { name : 'test1' } , function ( err , doc ) {
8080 counter ++ ;
8181 process . nextTick ( findOne ) ;
82-
82+
8383 if ( counter > POOL_SIZE ) {
8484 process . removeListener ( 'uncaughtException' , exceptionHandler ) ;
8585
@@ -93,12 +93,12 @@ var tests = testCase({
9393 }
9494 } ) ;
9595 } ;
96-
96+
9797 findOne ( ) ;
9898 } ) ;
9999 } ) ;
100100 } ,
101-
101+
102102 // Test a simple find
103103 shouldCorrectlyPerformSimpleFind : function ( test ) {
104104 client . createCollection ( 'test_find_simple' , function ( err , r ) {
@@ -115,10 +115,10 @@ var tests = testCase({
115115 collection . find ( function ( err , cursor ) {
116116 cursor . toArray ( function ( err , documents ) {
117117 test . equal ( 2 , documents . length ) ;
118-
118+
119119 collection . count ( function ( err , count ) {
120120 test . equal ( 2 , count ) ;
121-
121+
122122 // Fetch values by selection
123123 collection . find ( { 'a' : doc1 . a } , function ( err , cursor ) {
124124 cursor . toArray ( function ( err , documents ) {
@@ -885,8 +885,47 @@ var tests = testCase({
885885 } ) ;
886886 } ) ;
887887 } ,
888+
889+ 'Should correctly return new modified document' : function ( test ) {
890+ client . createCollection ( 'Should_correctly_return_new_modified_document' , function ( err , collection ) {
891+ var id = new client . bson_serializer . ObjectID ( ) ;
892+ var doc = { _id :id , a :1 , b :1 , c :{ a :1 , b :1 } } ;
893+
894+ collection . insert ( doc , { safe :true } , function ( err , result ) {
895+ test . ok ( err == null ) ;
896+
897+ // Find and modify returning the new object
898+ collection . findAndModify ( { _id :id } , [ ] , { $set : { 'c.c' : 100 } } , { new :true } , function ( err , item ) {
899+ test . equal ( doc . _id . toString ( ) , item . _id . toString ( ) ) ;
900+ test . equal ( doc . a , item . a ) ;
901+ test . equal ( doc . b , item . b ) ;
902+ test . equal ( doc . c . a , item . c . a ) ;
903+ test . equal ( doc . c . b , item . c . b ) ;
904+ test . equal ( 100 , item . c . c ) ;
905+ test . done ( ) ;
906+ } )
907+ } ) ;
908+ } ) ;
909+ } ,
910+
911+ // Should correctly execute findAndModify that is breaking in prod
912+ // shouldCorrectlyExecuteFindAndModify : function(test) {
913+ // client.createCollection('shouldCorrectlyExecuteFindAndModify', function(err, collection) {
914+ // var self = {_id : new client.bson_serializer.ObjectID()}
915+ // var _uuid = 'sddffdss'
916+ //
917+ // collection.findAndModify(
918+ // {_id: self._id, 'plays.uuid': _uuid},
919+ // [],
920+ // {$set : {'plays.$.active': true}},
921+ // {new: true, fields: {plays: 0, results: 0}, safe: true },
922+ // function(err, contest) {
923+ // test.done();
924+ // })
925+ // });
926+ // },
888927
889- noGlobalsLeaked : function ( test ) {
928+ noGlobalsLeaked : function ( test ) {
890929 var leaks = gleak . detectNew ( ) ;
891930 test . equal ( 0 , leaks . length , "global var leak detected: " + leaks . join ( ', ' ) ) ;
892931 test . done ( ) ;
0 commit comments