11import { expect } from 'chai' ;
22
3- import { Collection , type CommandStartedEvent , MongoClient , MongoServerError , ObjectId } from '../../mongodb' ;
3+ import {
4+ type Collection ,
5+ type CommandStartedEvent ,
6+ type MongoClient ,
7+ MongoServerError ,
8+ ObjectId
9+ } from '../../mongodb' ;
410import { setupDatabase } from '../shared' ;
511
612describe ( 'Collection (#findOneAnd...)' , function ( ) {
@@ -328,7 +334,7 @@ describe('Collection (#findOneAnd...)', function () {
328334 context ( 'when updating with an aggregation pipeline' , function ( ) {
329335 context ( 'when passing includeResultMetadata: true' , function ( ) {
330336 let client : MongoClient ;
331- let collection : Collection < { a : number , b : number } > ;
337+ let collection : Collection < { a : number ; b : number } > ;
332338
333339 beforeEach ( async function ( ) {
334340 client = this . configuration . newClient ( { } , { maxPoolSize : 1 } ) ;
@@ -341,22 +347,32 @@ describe('Collection (#findOneAnd...)', function () {
341347 await client ?. close ( ) ;
342348 } ) ;
343349
344- it ( 'the aggregation pipeline updates the matching document' , async function ( ) {
345- const { value : {
346- _id,
347- ...document
348- } } = await collection . findOneAndUpdate (
349- { a : 1 } ,
350- [ { $set : { a : { $add : [ 1 , '$a' ] } } } ] ,
351- { includeResultMetadata : true , returnDocument : 'after' }
352- ) ;
353- expect ( document ) . to . deep . equal ( { a : 2 , b : 1 } ) ;
354- } ) ;
350+ it (
351+ 'the aggregation pipeline updates the matching document' ,
352+ {
353+ requires : {
354+ mongodb : '>4.0'
355+ }
356+ } ,
357+ async function ( ) {
358+ const {
359+ value : { _id, ...document }
360+ } = await collection . findOneAndUpdate (
361+ { a : 1 } ,
362+ [ { $set : { a : { $add : [ 1 , '$a' ] } } } ] ,
363+ {
364+ includeResultMetadata : true ,
365+ returnDocument : 'after'
366+ }
367+ ) ;
368+ expect ( document ) . to . deep . equal ( { a : 2 , b : 1 } ) ;
369+ }
370+ ) ;
355371 } ) ;
356372
357373 context ( 'when passing includeResultMetadata: false' , function ( ) {
358374 let client : MongoClient ;
359- let collection : Collection < { a : number , b : number } > ;
375+ let collection : Collection < { a : number ; b : number } > ;
360376
361377 beforeEach ( async function ( ) {
362378 client = this . configuration . newClient ( { } , { maxPoolSize : 1 } ) ;
@@ -369,15 +385,22 @@ describe('Collection (#findOneAnd...)', function () {
369385 await client ?. close ( ) ;
370386 } ) ;
371387
372- it ( 'the aggregation pipeline updates the matching document' , async function ( ) {
373- const {
374- _id,
375- ...document
376- } = await collection . findOneAndUpdate ( { a : 1 } , [
377- { $set : { a : { $add : [ 1 , '$a' ] } } }
378- ] , { returnDocument : 'after' } ) ;
379- expect ( document ) . to . deep . equal ( { a : 2 , b : 1 } ) ;
380- } ) ;
388+ it (
389+ 'the aggregation pipeline updates the matching document' ,
390+ {
391+ requires : {
392+ mongodb : '>4.0'
393+ }
394+ } ,
395+ async function ( ) {
396+ const { _id, ...document } = await collection . findOneAndUpdate (
397+ { a : 1 } ,
398+ [ { $set : { a : { $add : [ 1 , '$a' ] } } } ] ,
399+ { returnDocument : 'after' }
400+ ) ;
401+ expect ( document ) . to . deep . equal ( { a : 2 , b : 1 } ) ;
402+ }
403+ ) ;
381404 } ) ;
382405 } ) ;
383406 } ) ;
0 commit comments