@@ -2282,164 +2282,40 @@ describe('crud - insert', function () {
2282
2282
}
2283
2283
} ) ;
2284
2284
2285
- it ( 'should return error on unordered insertMany with multiple unique key constraints' , {
2286
- // Add a tag that our runner can trigger on
2287
- // in this case we are setting that node needs to be higher than 0.10.X to run
2288
- metadata : {
2289
- requires : { topology : [ 'single' , 'replicaset' , 'ssl' , 'heap' , 'wiredtiger' ] }
2290
- } ,
2285
+ it ( 'should return error on unordered insertMany with multiple unique key constraints' , async ( ) => {
2286
+ const col = client . db ( ) . collection ( 'insertManyMultipleWriteErrors' ) ;
2291
2287
2292
- test : function ( done ) {
2293
- var configuration = this . configuration ;
2294
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
2295
- client . connect ( function ( err , client ) {
2296
- var db = client . db ( configuration . db ) ;
2297
- // Get collection
2298
- var col = db . collection ( 'insertManyMultipleWriteErrors' ) ;
2299
- col . drop ( function ( err , r ) {
2300
- expect ( r ) . to . not . exist ;
2288
+ await col . drop ( ) . catch ( ( ) => null ) ;
2301
2289
2302
- // Create unique index
2303
- col . createIndex ( { a : 1 } , { unique : true } , function ( err , r ) {
2304
- expect ( err ) . to . not . exist ;
2305
- test . ok ( r ) ;
2290
+ const createIndexRes = await col . createIndex ( { a : 1 } , { unique : true } ) ;
2291
+ expect ( createIndexRes ) . to . equal ( 'a_1' ) ;
2306
2292
2307
- col . insertMany (
2308
- [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] ,
2309
- { ordered : false } ,
2310
- function ( err , r ) {
2311
- expect ( r ) . to . not . exist ;
2312
- expect ( err ) . to . exist ;
2313
- expect ( err . result ) . to . exist ;
2314
- expect ( err . result . getWriteErrors ( ) ) . to . have . length ( 2 ) ;
2293
+ const insertManyRes = await col
2294
+ . insertMany ( [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] , { ordered : false } )
2295
+ . catch ( error => error ) ;
2315
2296
2316
- client . close ( done ) ;
2317
- }
2318
- ) ;
2319
- } ) ;
2320
- } ) ;
2321
- } ) ;
2322
- }
2323
- } ) ;
2324
-
2325
- it ( 'should return error on unordered insert with multiple unique key constraints' , {
2326
- // Add a tag that our runner can trigger on
2327
- // in this case we are setting that node needs to be higher than 0.10.X to run
2328
- metadata : {
2329
- requires : { topology : [ 'single' , 'replicaset' , 'ssl' , 'heap' , 'wiredtiger' ] }
2330
- } ,
2331
-
2332
- test : function ( done ) {
2333
- var configuration = this . configuration ;
2334
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
2335
- client . connect ( function ( err , client ) {
2336
- var db = client . db ( configuration . db ) ;
2337
- // Get collection
2338
- var col = db . collection ( 'insertManyMultipleWriteErrors1' ) ;
2339
- col . drop ( function ( err , r ) {
2340
- expect ( r ) . to . not . exist ;
2341
-
2342
- // Create unique index
2343
- col . createIndex ( { a : 1 } , { unique : true } , function ( err , r ) {
2344
- expect ( err ) . to . not . exist ;
2345
- test . ok ( r ) ;
2346
-
2347
- col . insert (
2348
- [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] ,
2349
- { ordered : false } ,
2350
- function ( err , r ) {
2351
- expect ( r ) . to . not . exist ;
2352
- expect ( err ) . to . exist ;
2353
- expect ( err . result ) . to . exist ;
2354
- expect ( err . result . getWriteErrors ( ) ) . to . have . length ( 2 ) ;
2355
-
2356
- client . close ( done ) ;
2357
- }
2358
- ) ;
2359
- } ) ;
2360
- } ) ;
2361
- } ) ;
2362
- }
2297
+ expect ( insertManyRes ) . to . be . instanceOf ( MongoBulkWriteError ) ;
2298
+ expect ( insertManyRes . result ) . to . exist ;
2299
+ // Unordered will hit both the a:1 inserts
2300
+ expect ( insertManyRes . result . getWriteErrors ( ) ) . to . have . length ( 2 ) ;
2363
2301
} ) ;
2364
2302
2365
- it ( 'should return error on ordered insertMany with multiple unique key constraints' , {
2366
- // Add a tag that our runner can trigger on
2367
- // in this case we are setting that node needs to be higher than 0.10.X to run
2368
- metadata : {
2369
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] }
2370
- } ,
2303
+ it ( 'should return error on ordered insertMany with multiple unique key constraints' , async ( ) => {
2304
+ const col = client . db ( ) . collection ( 'insertManyMultipleWriteErrors' ) ;
2371
2305
2372
- test : function ( done ) {
2373
- var configuration = this . configuration ;
2374
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
2375
- client . connect ( function ( err , client ) {
2376
- var db = client . db ( configuration . db ) ;
2377
- // Get collection
2378
- var col = db . collection ( 'insertManyMultipleWriteErrors2' ) ;
2379
- col . drop ( function ( /*err, r*/ ) {
2380
- // TODO: reenable once SERVER-36317 is resolved
2381
- // expect(r).to.not.exist;
2382
-
2383
- // Create unique index
2384
- col . createIndex ( { a : 1 } , { unique : true } , function ( err , r ) {
2385
- expect ( err ) . to . not . exist ;
2386
- test . ok ( r ) ;
2306
+ await col . drop ( ) . catch ( ( ) => null ) ;
2387
2307
2388
- col . insertMany (
2389
- [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] ,
2390
- { ordered : true } ,
2391
- function ( err , r ) {
2392
- expect ( r ) . to . not . exist ;
2393
- test . ok ( err != null ) ;
2394
- test . ok ( err . result ) ;
2308
+ const createIndexRes = await col . createIndex ( { a : 1 } , { unique : true } ) ;
2309
+ expect ( createIndexRes ) . to . equal ( 'a_1' ) ;
2395
2310
2396
- client . close ( done ) ;
2397
- }
2398
- ) ;
2399
- } ) ;
2400
- } ) ;
2401
- } ) ;
2402
- }
2403
- } ) ;
2311
+ const insertManyRes = await col
2312
+ . insertMany ( [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] , { ordered : true } )
2313
+ . catch ( error => error ) ;
2404
2314
2405
- it ( 'should return error on ordered insert with multiple unique key constraints' , {
2406
- // Add a tag that our runner can trigger on
2407
- // in this case we are setting that node needs to be higher than 0.10.X to run
2408
- metadata : {
2409
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] }
2410
- } ,
2411
-
2412
- test : function ( done ) {
2413
- var configuration = this . configuration ;
2414
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
2415
- client . connect ( function ( err , client ) {
2416
- var db = client . db ( configuration . db ) ;
2417
- // Get collection
2418
- var col = db . collection ( 'insertManyMultipleWriteErrors3' ) ;
2419
- col . drop ( function ( /*err, r*/ ) {
2420
- // TODO: reenable once SERVER-36317 is resolved
2421
- // expect(r).to.not.exist;
2422
-
2423
- // Create unique index
2424
- col . createIndex ( { a : 1 } , { unique : true } , function ( err , r ) {
2425
- expect ( err ) . to . not . exist ;
2426
- test . ok ( r ) ;
2427
-
2428
- col . insert (
2429
- [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] ,
2430
- { ordered : true } ,
2431
- function ( err , r ) {
2432
- expect ( r ) . to . not . exist ;
2433
- test . ok ( err != null ) ;
2434
- test . ok ( err . result ) ;
2435
-
2436
- client . close ( done ) ;
2437
- }
2438
- ) ;
2439
- } ) ;
2440
- } ) ;
2441
- } ) ;
2442
- }
2315
+ expect ( insertManyRes ) . to . be . instanceOf ( MongoBulkWriteError ) ;
2316
+ expect ( insertManyRes . result ) . to . exist ;
2317
+ // Ordered will hit only the second a:1 insert
2318
+ expect ( insertManyRes . result . getWriteErrors ( ) ) . to . have . length ( 1 ) ;
2443
2319
} ) ;
2444
2320
2445
2321
it ( 'Correctly allow forceServerObjectId for insertOne' , {
0 commit comments