@@ -118,38 +118,44 @@ async function runUnifiedTest(
118
118
// The test runner MUST use the internal MongoClient for these operations.
119
119
if ( unifiedSuite . initialData ) {
120
120
trace ( 'initialData' ) ;
121
- for ( const collData of unifiedSuite . initialData ) {
122
- const db = utilClient . db ( collData . databaseName ) ;
123
- const collection = db . collection ( collData . collectionName , {
121
+ for ( const { databaseName , collectionName } of unifiedSuite . initialData ) {
122
+ const db = utilClient . db ( databaseName ) ;
123
+ const collection = db . collection ( collectionName , {
124
124
writeConcern : { w : 'majority' }
125
125
} ) ;
126
126
127
127
trace ( 'listCollections' ) ;
128
- const collectionList = await db
129
- . listCollections ( { name : collData . collectionName } )
130
- . toArray ( ) ;
128
+ const collectionList = await db . listCollections ( { name : collectionName } ) . toArray ( ) ;
131
129
if ( collectionList . length !== 0 ) {
132
130
trace ( 'drop' ) ;
133
131
expect ( await collection . drop ( ) ) . to . be . true ;
134
132
}
135
133
}
136
134
137
- for ( const collData of unifiedSuite . initialData ) {
138
- const db = utilClient . db ( collData . databaseName ) ;
139
- const collection = db . collection ( collData . collectionName , {
135
+ for ( const {
136
+ databaseName,
137
+ collectionName,
138
+ createOptions,
139
+ documents = [ ]
140
+ } of unifiedSuite . initialData ) {
141
+ const db = utilClient . db ( databaseName ) ;
142
+ const collection = db . collection ( collectionName , {
140
143
writeConcern : { w : 'majority' }
141
144
} ) ;
142
145
143
- if ( ! collData . documents ? .length ) {
146
+ if ( createOptions || ! documents . length ) {
144
147
trace ( 'createCollection' ) ;
145
- await db . createCollection ( collData . collectionName , {
148
+ const options = createOptions ?? { } ;
149
+ await db . createCollection ( collectionName , {
150
+ ...options ,
146
151
writeConcern : { w : 'majority' }
147
152
} ) ;
148
- continue ;
149
153
}
150
154
151
- trace ( 'insertMany' ) ;
152
- await collection . insertMany ( collData . documents ) ;
155
+ if ( documents . length > 0 ) {
156
+ trace ( 'insertMany' ) ;
157
+ await collection . insertMany ( documents ) ;
158
+ }
153
159
}
154
160
}
155
161
0 commit comments