@@ -2141,164 +2141,40 @@ describe('crud - insert', function () {
2141
2141
}
2142
2142
} ) ;
2143
2143
2144
- it ( 'should return error on unordered insertMany with multiple unique key constraints' , {
2145
- // Add a tag that our runner can trigger on
2146
- // in this case we are setting that node needs to be higher than 0.10.X to run
2147
- metadata : {
2148
- requires : { topology : [ 'single' , 'replicaset' , 'ssl' , 'heap' , 'wiredtiger' ] }
2149
- } ,
2144
+ it ( 'should return error on unordered insertMany with multiple unique key constraints' , async ( ) => {
2145
+ const col = client . db ( ) . collection ( 'insertManyMultipleWriteErrors' ) ;
2150
2146
2151
- test : function ( done ) {
2152
- var configuration = this . configuration ;
2153
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
2154
- client . connect ( function ( err , client ) {
2155
- var db = client . db ( configuration . db ) ;
2156
- // Get collection
2157
- var col = db . collection ( 'insertManyMultipleWriteErrors' ) ;
2158
- col . drop ( function ( err , r ) {
2159
- expect ( r ) . to . not . exist ;
2147
+ await col . drop ( ) . catch ( ( ) => null ) ;
2160
2148
2161
- // Create unique index
2162
- col . createIndex ( { a : 1 } , { unique : true } , function ( err , r ) {
2163
- expect ( err ) . to . not . exist ;
2164
- test . ok ( r ) ;
2149
+ const createIndexRes = await col . createIndex ( { a : 1 } , { unique : true } ) ;
2150
+ expect ( createIndexRes ) . to . equal ( 'a_1' ) ;
2165
2151
2166
- col . insertMany (
2167
- [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] ,
2168
- { ordered : false } ,
2169
- function ( err , r ) {
2170
- expect ( r ) . to . not . exist ;
2171
- expect ( err ) . to . exist ;
2172
- expect ( err . result ) . to . exist ;
2173
- expect ( err . result . getWriteErrors ( ) ) . to . have . length ( 2 ) ;
2152
+ const insertManyRes = await col
2153
+ . insertMany ( [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] , { ordered : false } )
2154
+ . catch ( error => error ) ;
2174
2155
2175
- client . close ( done ) ;
2176
- }
2177
- ) ;
2178
- } ) ;
2179
- } ) ;
2180
- } ) ;
2181
- }
2182
- } ) ;
2183
-
2184
- it ( 'should return error on unordered insert with multiple unique key constraints' , {
2185
- // Add a tag that our runner can trigger on
2186
- // in this case we are setting that node needs to be higher than 0.10.X to run
2187
- metadata : {
2188
- requires : { topology : [ 'single' , 'replicaset' , 'ssl' , 'heap' , 'wiredtiger' ] }
2189
- } ,
2190
-
2191
- test : function ( done ) {
2192
- var configuration = this . configuration ;
2193
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
2194
- client . connect ( function ( err , client ) {
2195
- var db = client . db ( configuration . db ) ;
2196
- // Get collection
2197
- var col = db . collection ( 'insertManyMultipleWriteErrors1' ) ;
2198
- col . drop ( function ( err , r ) {
2199
- expect ( r ) . to . not . exist ;
2200
-
2201
- // Create unique index
2202
- col . createIndex ( { a : 1 } , { unique : true } , function ( err , r ) {
2203
- expect ( err ) . to . not . exist ;
2204
- test . ok ( r ) ;
2205
-
2206
- col . insert (
2207
- [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] ,
2208
- { ordered : false } ,
2209
- function ( err , r ) {
2210
- expect ( r ) . to . not . exist ;
2211
- expect ( err ) . to . exist ;
2212
- expect ( err . result ) . to . exist ;
2213
- expect ( err . result . getWriteErrors ( ) ) . to . have . length ( 2 ) ;
2214
-
2215
- client . close ( done ) ;
2216
- }
2217
- ) ;
2218
- } ) ;
2219
- } ) ;
2220
- } ) ;
2221
- }
2156
+ expect ( insertManyRes ) . to . be . instanceOf ( MongoBulkWriteError ) ;
2157
+ expect ( insertManyRes . result ) . to . exist ;
2158
+ // Unordered will hit both the a:1 inserts
2159
+ expect ( insertManyRes . result . getWriteErrors ( ) ) . to . have . length ( 2 ) ;
2222
2160
} ) ;
2223
2161
2224
- it ( 'should return error on ordered insertMany with multiple unique key constraints' , {
2225
- // Add a tag that our runner can trigger on
2226
- // in this case we are setting that node needs to be higher than 0.10.X to run
2227
- metadata : {
2228
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] }
2229
- } ,
2162
+ it ( 'should return error on ordered insertMany with multiple unique key constraints' , async ( ) => {
2163
+ const col = client . db ( ) . collection ( 'insertManyMultipleWriteErrors' ) ;
2230
2164
2231
- test : function ( done ) {
2232
- var configuration = this . configuration ;
2233
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
2234
- client . connect ( function ( err , client ) {
2235
- var db = client . db ( configuration . db ) ;
2236
- // Get collection
2237
- var col = db . collection ( 'insertManyMultipleWriteErrors2' ) ;
2238
- col . drop ( function ( /*err, r*/ ) {
2239
- // TODO: reenable once SERVER-36317 is resolved
2240
- // expect(r).to.not.exist;
2241
-
2242
- // Create unique index
2243
- col . createIndex ( { a : 1 } , { unique : true } , function ( err , r ) {
2244
- expect ( err ) . to . not . exist ;
2245
- test . ok ( r ) ;
2165
+ await col . drop ( ) . catch ( ( ) => null ) ;
2246
2166
2247
- col . insertMany (
2248
- [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] ,
2249
- { ordered : true } ,
2250
- function ( err , r ) {
2251
- expect ( r ) . to . not . exist ;
2252
- test . ok ( err != null ) ;
2253
- test . ok ( err . result ) ;
2167
+ const createIndexRes = await col . createIndex ( { a : 1 } , { unique : true } ) ;
2168
+ expect ( createIndexRes ) . to . equal ( 'a_1' ) ;
2254
2169
2255
- client . close ( done ) ;
2256
- }
2257
- ) ;
2258
- } ) ;
2259
- } ) ;
2260
- } ) ;
2261
- }
2262
- } ) ;
2170
+ const insertManyRes = await col
2171
+ . insertMany ( [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] , { ordered : true } )
2172
+ . catch ( error => error ) ;
2263
2173
2264
- it ( 'should return error on ordered insert with multiple unique key constraints' , {
2265
- // Add a tag that our runner can trigger on
2266
- // in this case we are setting that node needs to be higher than 0.10.X to run
2267
- metadata : {
2268
- requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] }
2269
- } ,
2270
-
2271
- test : function ( done ) {
2272
- var configuration = this . configuration ;
2273
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
2274
- client . connect ( function ( err , client ) {
2275
- var db = client . db ( configuration . db ) ;
2276
- // Get collection
2277
- var col = db . collection ( 'insertManyMultipleWriteErrors3' ) ;
2278
- col . drop ( function ( /*err, r*/ ) {
2279
- // TODO: reenable once SERVER-36317 is resolved
2280
- // expect(r).to.not.exist;
2281
-
2282
- // Create unique index
2283
- col . createIndex ( { a : 1 } , { unique : true } , function ( err , r ) {
2284
- expect ( err ) . to . not . exist ;
2285
- test . ok ( r ) ;
2286
-
2287
- col . insert (
2288
- [ { a : 1 } , { a : 2 } , { a : 1 } , { a : 3 } , { a : 1 } ] ,
2289
- { ordered : true } ,
2290
- function ( err , r ) {
2291
- expect ( r ) . to . not . exist ;
2292
- test . ok ( err != null ) ;
2293
- test . ok ( err . result ) ;
2294
-
2295
- client . close ( done ) ;
2296
- }
2297
- ) ;
2298
- } ) ;
2299
- } ) ;
2300
- } ) ;
2301
- }
2174
+ expect ( insertManyRes ) . to . be . instanceOf ( MongoBulkWriteError ) ;
2175
+ expect ( insertManyRes . result ) . to . exist ;
2176
+ // Ordered will hit only the second a:1 insert
2177
+ expect ( insertManyRes . result . getWriteErrors ( ) ) . to . have . length ( 1 ) ;
2302
2178
} ) ;
2303
2179
2304
2180
it ( 'Correctly allow forceServerObjectId for insertOne' , {
0 commit comments