@@ -123,11 +123,14 @@ describe('CRUD API explain option', function () {
123
123
describe ( 'explain helpers w/ maxTimeMS' , function ( ) {
124
124
let client : MongoClient ;
125
125
const commands : CommandStartedEvent [ ] = [ ] ;
126
+ let collection : Collection ;
126
127
127
128
beforeEach ( async function ( ) {
128
129
client = this . configuration . newClient ( { } , { monitorCommands : true } ) ;
129
130
await client . connect ( ) ;
130
131
132
+ collection = await client . db ( 'explain-test' ) . createCollection ( 'bar' ) ;
133
+
131
134
client . on ( 'commandStarted' , filterForCommands ( 'explain' , commands ) ) ;
132
135
commands . length = 0 ;
133
136
} ) ;
@@ -139,7 +142,6 @@ describe('CRUD API explain option', function () {
139
142
describe ( 'cursor explain commands' , function ( ) {
140
143
describe ( 'when maxTimeMS is specified via a cursor explain method, it sets the property on the command' , function ( ) {
141
144
test ( 'find()' , async function ( ) {
142
- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
143
145
await collection
144
146
. find ( { name : 'john doe' } )
145
147
. explain ( { maxTimeMS : 2000 , verbosity : 'queryPlanner' } ) ;
@@ -149,8 +151,6 @@ describe('CRUD API explain option', function () {
149
151
} ) ;
150
152
151
153
test ( 'aggregate()' , async function ( ) {
152
- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
153
-
154
154
await collection
155
155
. aggregate ( [ { $match : { name : 'john doe' } } ] )
156
156
. explain ( { maxTimeMS : 2000 , verbosity : 'queryPlanner' } ) ;
@@ -161,19 +161,13 @@ describe('CRUD API explain option', function () {
161
161
} ) ;
162
162
163
163
it ( 'when maxTimeMS is not specified, it is not attached to the explain command' , async function ( ) {
164
- // Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
165
- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
166
-
167
164
await collection . find ( { name : 'john doe' } ) . explain ( { verbosity : 'queryPlanner' } ) ;
168
165
169
166
const [ { command } ] = commands ;
170
167
expect ( command ) . not . to . have . property ( 'maxTimeMS' ) ;
171
168
} ) ;
172
169
173
170
it ( 'when maxTimeMS is specified as an explain option and a command-level option, the explain option takes precedence' , async function ( ) {
174
- // Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
175
- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
176
-
177
171
await collection
178
172
. find (
179
173
{ } ,
@@ -194,15 +188,12 @@ describe('CRUD API explain option', function () {
194
188
195
189
describe ( 'regular commands w/ explain' , function ( ) {
196
190
it ( 'when maxTimeMS is specified as an explain option and a command-level option, the explain option takes precedence' , async function ( ) {
197
- // Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
198
- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
199
-
200
191
await collection . deleteMany (
201
192
{ } ,
202
193
{
203
194
maxTimeMS : 1000 ,
204
195
explain : {
205
- verbosity : true ,
196
+ verbosity : 'queryPlanner' ,
206
197
maxTimeMS : 2000
207
198
}
208
199
}
@@ -214,7 +205,6 @@ describe('CRUD API explain option', function () {
214
205
215
206
describe ( 'when maxTimeMS is specified as an explain option' , function ( ) {
216
207
it ( 'attaches maxTimeMS to the explain command' , async function ( ) {
217
- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
218
208
await collection . deleteMany (
219
209
{ } ,
220
210
{ explain : { maxTimeMS : 2000 , verbosity : 'queryPlanner' } }
@@ -226,8 +216,6 @@ describe('CRUD API explain option', function () {
226
216
} ) ;
227
217
228
218
it ( 'when maxTimeMS is not specified, it is not attached to the explain command' , async function ( ) {
229
- const collection = client . db ( 'explain-test' ) . collection ( 'collection' ) ;
230
-
231
219
await collection . deleteMany ( { } , { explain : { verbosity : 'queryPlanner' } } ) ;
232
220
233
221
const [ { command } ] = commands ;
0 commit comments