@@ -781,126 +781,6 @@ describe('Find', function () {
781
781
}
782
782
} ) ;
783
783
784
- /**
785
- * Test findOneAndUpdate a document
786
- */
787
- it ( 'shouldCorrectlyfindOneAndUpdateDocument' , {
788
- metadata : {
789
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] }
790
- } ,
791
-
792
- test : function ( done ) {
793
- var configuration = this . configuration ;
794
- var db = client . db ( configuration . db ) ;
795
- db . dropCollection ( 'test_find_and_modify_a_document_1' )
796
- . catch ( ( ) => null )
797
- . finally ( ( ) => {
798
- db . createCollection ( 'test_find_and_modify_a_document_1' , function ( err , collection ) {
799
- expect ( err ) . to . not . exist ;
800
-
801
- // Test return new document on change
802
- collection . insert ( { a : 1 , b : 2 } , configuration . writeConcernMax ( ) , function ( err ) {
803
- expect ( err ) . to . not . exist ;
804
-
805
- // Let's modify the document in place
806
- collection . findOneAndUpdate (
807
- { a : 1 } ,
808
- { $set : { b : 3 } } ,
809
- { returnDocument : ReturnDocument . AFTER } ,
810
- function ( err , updated_doc ) {
811
- expect ( err ) . to . not . exist ;
812
- test . equal ( 1 , updated_doc . value . a ) ;
813
- test . equal ( 3 , updated_doc . value . b ) ;
814
-
815
- // Test return old document on change
816
- collection . insert (
817
- { a : 2 , b : 2 } ,
818
- configuration . writeConcernMax ( ) ,
819
- function ( err ) {
820
- expect ( err ) . to . not . exist ;
821
-
822
- // Let's modify the document in place
823
- collection . findOneAndUpdate (
824
- { a : 2 } ,
825
- { $set : { b : 3 } } ,
826
- configuration . writeConcernMax ( ) ,
827
- function ( err , result ) {
828
- expect ( err ) . to . not . exist ;
829
- test . equal ( 2 , result . value . a ) ;
830
- test . equal ( 2 , result . value . b ) ;
831
-
832
- // Test remove object on change
833
- collection . insert (
834
- { a : 3 , b : 2 } ,
835
- configuration . writeConcernMax ( ) ,
836
- function ( err ) {
837
- expect ( err ) . to . not . exist ;
838
- // Let's modify the document in place
839
- collection . findOneAndUpdate (
840
- { a : 3 } ,
841
- { $set : { b : 3 } } ,
842
- { remove : true } ,
843
- function ( err , updated_doc ) {
844
- expect ( err ) . to . not . exist ;
845
- test . equal ( 3 , updated_doc . value . a ) ;
846
- test . equal ( 2 , updated_doc . value . b ) ;
847
-
848
- // Let's upsert!
849
- collection . findOneAndUpdate (
850
- { a : 4 } ,
851
- { $set : { b : 3 } } ,
852
- { returnDocument : ReturnDocument . AFTER , upsert : true } ,
853
- function ( err , updated_doc ) {
854
- expect ( err ) . to . not . exist ;
855
- test . equal ( 4 , updated_doc . value . a ) ;
856
- test . equal ( 3 , updated_doc . value . b ) ;
857
-
858
- // Test selecting a subset of fields
859
- collection . insert (
860
- { a : 100 , b : 101 } ,
861
- configuration . writeConcernMax ( ) ,
862
- function ( err , r ) {
863
- expect ( err ) . to . not . exist ;
864
-
865
- collection . findOneAndUpdate (
866
- { a : 100 } ,
867
- { $set : { b : 5 } } ,
868
- {
869
- returnDocument : ReturnDocument . AFTER ,
870
- projection : { b : 1 }
871
- } ,
872
- function ( err , updated_doc ) {
873
- expect ( err ) . to . not . exist ;
874
- test . equal ( 2 , Object . keys ( updated_doc . value ) . length ) ;
875
- test . equal (
876
- r . insertedIds [ 0 ] . toHexString ( ) ,
877
- updated_doc . value . _id . toHexString ( )
878
- ) ;
879
- test . equal ( 5 , updated_doc . value . b ) ;
880
- test . equal ( 'undefined' , typeof updated_doc . value . a ) ;
881
- client . close ( done ) ;
882
- }
883
- ) ;
884
- }
885
- ) ;
886
- }
887
- ) ;
888
- }
889
- ) ;
890
- }
891
- ) ;
892
- }
893
- ) ;
894
- }
895
- ) ;
896
- }
897
- ) ;
898
- } ) ;
899
- } ) ;
900
- } ) ;
901
- }
902
- } ) ;
903
-
904
784
/**
905
785
* Test findOneAndUpdate a document with fields
906
786
*/
@@ -925,8 +805,8 @@ describe('Find', function () {
925
805
{ $set : { b : 3 } } ,
926
806
{ returnDocument : ReturnDocument . AFTER , projection : { a : 1 } } ,
927
807
function ( err , updated_doc ) {
928
- test . equal ( 2 , Object . keys ( updated_doc . value ) . length ) ;
929
- test . equal ( 1 , updated_doc . value . a ) ;
808
+ test . equal ( 2 , Object . keys ( updated_doc ) . length ) ;
809
+ test . equal ( 1 , updated_doc . a ) ;
930
810
client . close ( done ) ;
931
811
}
932
812
) ;
@@ -981,53 +861,6 @@ describe('Find', function () {
981
861
}
982
862
} ) ;
983
863
984
- /**
985
- * Test findOneAndUpdate a document
986
- */
987
- it ( 'Should Correctly Handle findOneAndUpdate Duplicate Key Error' , {
988
- metadata : {
989
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] }
990
- } ,
991
-
992
- test : function ( done ) {
993
- var configuration = this . configuration ;
994
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
995
- client . connect ( function ( err , client ) {
996
- expect ( err ) . to . not . exist ;
997
- var db = client . db ( configuration . db ) ;
998
- db . createCollection ( 'findOneAndUpdateDuplicateKeyError' , function ( err , collection ) {
999
- expect ( err ) . to . not . exist ;
1000
- collection . createIndex (
1001
- [ 'name' , 1 ] ,
1002
- { unique : true , writeConcern : { w : 1 } } ,
1003
- function ( err ) {
1004
- expect ( err ) . to . not . exist ;
1005
- // Test return new document on change
1006
- collection . insert (
1007
- [ { name : 'test1' } , { name : 'test2' } ] ,
1008
- configuration . writeConcernMax ( ) ,
1009
- function ( err ) {
1010
- expect ( err ) . to . not . exist ;
1011
- // Let's modify the document in place
1012
- collection . findOneAndUpdate (
1013
- { name : 'test1' } ,
1014
- { $set : { name : 'test2' } } ,
1015
- { } ,
1016
- function ( err , updated_doc ) {
1017
- expect ( err ) . to . exist ;
1018
- expect ( updated_doc ) . to . not . exist ;
1019
- client . close ( done ) ;
1020
- }
1021
- ) ;
1022
- }
1023
- ) ;
1024
- }
1025
- ) ;
1026
- } ) ;
1027
- } ) ;
1028
- }
1029
- } ) ;
1030
-
1031
864
it ( 'Should correctly return null when attempting to modify a non-existing document' , {
1032
865
metadata : {
1033
866
requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] }
@@ -1047,7 +880,7 @@ describe('Find', function () {
1047
880
{ $set : { name : 'test2' } } ,
1048
881
{ } ,
1049
882
function ( err , updated_doc ) {
1050
- expect ( updated_doc . value ) . to . not . exist ;
883
+ expect ( updated_doc ) . to . not . exist ;
1051
884
test . ok ( err == null || err . errmsg . match ( 'No matching object found' ) ) ;
1052
885
client . close ( done ) ;
1053
886
}
@@ -1168,8 +1001,8 @@ describe('Find', function () {
1168
1001
{ $set : { b : 3 } } ,
1169
1002
{ returnDocument : ReturnDocument . AFTER } ,
1170
1003
function ( err , result ) {
1171
- test . equal ( 2 , result . value . a ) ;
1172
- test . equal ( 3 , result . value . b ) ;
1004
+ test . equal ( 2 , result . a ) ;
1005
+ test . equal ( 3 , result . b ) ;
1173
1006
p_client . close ( done ) ;
1174
1007
}
1175
1008
) ;
@@ -1260,12 +1093,12 @@ describe('Find', function () {
1260
1093
{ $set : { 'c.c' : 100 } } ,
1261
1094
{ returnDocument : ReturnDocument . AFTER } ,
1262
1095
function ( err , item ) {
1263
- test . equal ( doc . _id . toString ( ) , item . value . _id . toString ( ) ) ;
1264
- test . equal ( doc . a , item . value . a ) ;
1265
- test . equal ( doc . b , item . value . b ) ;
1266
- test . equal ( doc . c . a , item . value . c . a ) ;
1267
- test . equal ( doc . c . b , item . value . c . b ) ;
1268
- test . equal ( 100 , item . value . c . c ) ;
1096
+ test . equal ( doc . _id . toString ( ) , item . _id . toString ( ) ) ;
1097
+ test . equal ( doc . a , item . a ) ;
1098
+ test . equal ( doc . b , item . b ) ;
1099
+ test . equal ( doc . c . a , item . c . a ) ;
1100
+ test . equal ( doc . c . b , item . c . b ) ;
1101
+ test . equal ( 100 , item . c . c ) ;
1269
1102
client . close ( done ) ;
1270
1103
}
1271
1104
) ;
@@ -1455,7 +1288,7 @@ describe('Find', function () {
1455
1288
{ returnDocument : ReturnDocument . AFTER } ,
1456
1289
function ( err , updated_doc ) {
1457
1290
expect ( err ) . to . not . exist ;
1458
- expect ( updated_doc . value ) . to . not . exist ;
1291
+ expect ( updated_doc ) . to . not . exist ;
1459
1292
client . close ( done ) ;
1460
1293
}
1461
1294
) ;
@@ -2327,8 +2160,8 @@ describe('Find', function () {
2327
2160
{ $set : { b : 3 } } ,
2328
2161
{ returnDocument : ReturnDocument . AFTER } ,
2329
2162
function ( err , updated_doc ) {
2330
- test . equal ( 1 , updated_doc . value . a ) ;
2331
- test . equal ( 3 , updated_doc . value . b ) ;
2163
+ test . equal ( 1 , updated_doc . a ) ;
2164
+ test . equal ( 3 , updated_doc . b ) ;
2332
2165
2333
2166
client . close ( done ) ;
2334
2167
}
0 commit comments