@@ -369,7 +369,7 @@ exports['Should correctly perform ordered upsert with custom _id'] = {
369
369
}
370
370
}
371
371
372
- exports [ 'Should throw an error when no operations in ordered batch' ] = {
372
+ exports [ 'Should return an error when no operations in ordered batch' ] = {
373
373
metadata : { requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] } } ,
374
374
375
375
// The actual test we wish to run
@@ -378,18 +378,15 @@ exports['Should throw an error when no operations in ordered batch'] = {
378
378
db . open ( function ( err , db ) {
379
379
// Get the collection
380
380
var col = db . collection ( 'batch_write_ordered_ops_8' ) ;
381
- var threw = false ;
382
381
383
- try {
384
- // Initialize the Ordered Batch
385
- col . initializeOrderedBulkOp ( ) . execute ( function ( err , result ) { } ) ;
386
- } catch ( err ) {
387
- threw = true ;
388
- }
382
+ // Initialize the Ordered Batch
383
+ col . initializeOrderedBulkOp ( ) . execute ( function ( err , result ) {
384
+ test . equal ( err instanceof Error , true ) ;
385
+ test . equal ( err . message , 'Invalid Operation, no operations specified' ) ;
389
386
390
- test . equal ( true , threw ) ;
391
- db . close ( ) ;
392
- test . done ( ) ;
387
+ db . close ( ) ;
388
+ test . done ( ) ;
389
+ } ) ;
393
390
} ) ;
394
391
}
395
392
}
@@ -874,7 +871,7 @@ exports['Should prohibit batch finds with no selector'] = {
874
871
}
875
872
}
876
873
877
- exports [ 'Should throw an error when no operations in unordered batch' ] = {
874
+ exports [ 'Should return an error when no operations in unordered batch' ] = {
878
875
metadata : { requires : { topology : [ 'single' , 'replicaset' , 'ssl' , 'heap' , 'wiredtiger' ] } } ,
879
876
880
877
// The actual test we wish to run
@@ -883,18 +880,15 @@ exports['Should throw an error when no operations in unordered batch'] = {
883
880
db . open ( function ( err , db ) {
884
881
// Get the collection
885
882
var col = db . collection ( 'batch_write_ordered_ops_8' ) ;
886
- var threw = false ;
887
883
888
- try {
889
- // Initialize the Ordered Batch
890
- col . initializeUnorderedBulkOp ( ) . execute ( configuration . writeConcernMax ( ) , function ( err , result ) { } ) ;
891
- } catch ( err ) {
892
- threw = true ;
893
- }
884
+ // Initialize the Ordered Batch
885
+ col . initializeUnorderedBulkOp ( ) . execute ( configuration . writeConcernMax ( ) , function ( err , result ) {
886
+ test . equal ( err instanceof Error , true ) ;
887
+ test . equal ( err . message , 'Invalid Operation, no operations specified' ) ;
894
888
895
- test . equal ( true , threw ) ;
896
- db . close ( ) ;
897
- test . done ( ) ;
889
+ db . close ( ) ;
890
+ test . done ( ) ;
891
+ } ) ;
898
892
} ) ;
899
893
}
900
894
}
@@ -1228,3 +1222,56 @@ exports['Should correctly handle bulk operation split for unordered bulk operati
1228
1222
} ) ;
1229
1223
}
1230
1224
}
1225
+
1226
+ exports [ 'Should return an error instead of throwing when no operations are provided for ordered bulk operation execute' ] = {
1227
+ metadata : { requires : { mongodb : ">=2.6.0" , topology : 'single' , node : ">0.10.0" } } ,
1228
+ test : function ( configure , test ) {
1229
+ var db = configure . newDbInstance ( { w : 1 } , { poolSize : 1 } ) ;
1230
+
1231
+ db . open ( function ( err , db ) {
1232
+ db . collection ( 'doesnt_matter' ) . insertMany ( [ ] , function ( err , r ) {
1233
+ test . equal ( err instanceof Error , true ) ;
1234
+ test . equal ( err . message , 'Invalid Operation, no operations specified' ) ;
1235
+ db . close ( ) ;
1236
+ test . done ( ) ;
1237
+ } ) ;
1238
+ } ) ;
1239
+ }
1240
+ }
1241
+
1242
+ exports [ 'Should return an error instead of throwing when no operations are provided for unordered bulk operation execute' ] = {
1243
+ metadata : { requires : { mongodb : ">=2.6.0" , topology : 'single' , node : ">0.10.0" } } ,
1244
+ test : function ( configure , test ) {
1245
+ var db = configure . newDbInstance ( { w : 1 } , { poolSize : 1 } ) ;
1246
+
1247
+ db . open ( function ( err , db ) {
1248
+ db . collection ( 'doesnt_matter' ) . insertMany ( [ ] , { ordered : false } , function ( err , r ) {
1249
+ test . equal ( err instanceof Error , true ) ;
1250
+ test . equal ( err . message , 'Invalid Operation, no operations specified' ) ;
1251
+ db . close ( ) ;
1252
+ test . done ( ) ;
1253
+ } ) ;
1254
+ } ) ;
1255
+ }
1256
+ }
1257
+
1258
+ exports [ 'Should return an error instead of throwing when an empty bulk operation is submitted (with promise)' ] = {
1259
+ metadata : { requires : { promises : true , node : ">0.12.0" } } ,
1260
+ test : function ( configure , test ) {
1261
+ var db = configure . newDbInstance ( { w : 1 } , { poolSize : 1 } ) ;
1262
+
1263
+ return db . open ( )
1264
+ . then ( function ( ) { return db . collection ( 'doesnt_matter' ) . insertMany ( [ ] ) ; } )
1265
+ . then ( function ( ) {
1266
+ test . equal ( false , true ) ; // this should not happen!
1267
+ } )
1268
+ . catch ( function ( err ) {
1269
+ test . equal ( err instanceof Error , true ) ;
1270
+ test . equal ( err . message , 'Invalid Operation, no operations specified' ) ;
1271
+ } )
1272
+ . then ( function ( ) {
1273
+ db . close ( ) ;
1274
+ test . done ( ) ;
1275
+ } ) ;
1276
+ }
1277
+ }
0 commit comments