@@ -6,6 +6,7 @@ import { finished } from 'stream/promises';
6
6
import {
7
7
Collection ,
8
8
CommandFailedEvent ,
9
+ type CommandStartedEvent ,
9
10
CommandSucceededEvent ,
10
11
MongoBulkWriteError ,
11
12
type MongoClient ,
@@ -1152,4 +1153,53 @@ describe('CRUD API', function () {
1152
1153
} ) ;
1153
1154
}
1154
1155
} ) ;
1156
+
1157
+ describe ( 'sort support' , function ( ) {
1158
+ let client : MongoClient ;
1159
+ let events : Array < CommandStartedEvent > ;
1160
+ let collection : Collection ;
1161
+
1162
+ beforeEach ( async function ( ) {
1163
+ client = this . configuration . newClient ( { monitorCommands : true } ) ;
1164
+ events = [ ] ;
1165
+ client . on ( 'commandStarted' , commandStarted =>
1166
+ commandStarted . commandName === 'update' ? events . push ( commandStarted ) : null
1167
+ ) ;
1168
+
1169
+ collection = client . db ( 'updateManyTest' ) . collection ( 'updateManyTest' ) ;
1170
+ await collection . drop ( ) . catch ( ( ) => null ) ;
1171
+ await collection . insertMany ( [ { a : 1 } , { a : 2 } ] ) ;
1172
+ } ) ;
1173
+
1174
+ afterEach ( async function ( ) {
1175
+ await collection . drop ( ) . catch ( ( ) => null ) ;
1176
+ await client . close ( ) ;
1177
+ } ) ;
1178
+
1179
+ describe ( 'collection.updateMany()' , ( ) => {
1180
+ it ( 'does not attach a sort property if one is specified' , async function ( ) {
1181
+ // @ts -expect-error: sort is not supported
1182
+ await collection . updateMany ( { a : { $gte : 1 } } , { $set : { b : 1 } } , { sort : { a : 1 } } ) ;
1183
+
1184
+ expect ( events ) . to . have . lengthOf ( 1 ) ;
1185
+ const [ updateEvent ] = events ;
1186
+ expect ( updateEvent . commandName ) . to . equal ( 'update' ) ;
1187
+ expect ( updateEvent . command . updates [ 0 ] ) . to . not . have . property ( 'sort' ) ;
1188
+ } ) ;
1189
+ } ) ;
1190
+
1191
+ describe ( 'collection.bulkWrite([{updateMany}])' , ( ) => {
1192
+ it ( 'does not attach a sort property if one is specified' , async function ( ) {
1193
+ await collection . bulkWrite ( [
1194
+ // @ts -expect-error: sort is not supported
1195
+ { updateMany : { filter : { a : { $gte : 1 } } , update : { $set : { b : 1 } } , sort : { a : 1 } } }
1196
+ ] ) ;
1197
+
1198
+ expect ( events ) . to . have . lengthOf ( 1 ) ;
1199
+ const [ updateEvent ] = events ;
1200
+ expect ( updateEvent . commandName ) . to . equal ( 'update' ) ;
1201
+ expect ( updateEvent . command . updates [ 0 ] ) . to . not . have . property ( 'sort' ) ;
1202
+ } ) ;
1203
+ } ) ;
1204
+ } ) ;
1155
1205
} ) ;
0 commit comments