@@ -64,7 +64,7 @@ Fetches the first document that matches the filter. Returns `null` if document w
6464``` typescript
6565updateOne = async <U extends T = T >(
6666 filter : Filter <U >,
67- updateFn : (doc : U ) => Partial <U >,
67+ updateFilterOrFn : (doc : U ) => Partial < U > | UpdateFilter <U >,
6868 updateConfig : UpdateConfig = {},
6969 updateOptions : UpdateOptions = {},
7070): Promise < U | null >
@@ -81,13 +81,18 @@ const updatedUser = await userService.updateOne(
8181 (doc ) => ({ fullName: ' Updated fullname' }),
8282 { publishEvents: false }
8383);
84+
85+ const updatedUserWithUpdateFilter = await userService .updateOne (
86+ { _id: u ._id },
87+ { $set: { fullName: ' Updated fullname' }},
88+ );
8489```
8590
8691Updates a single document and returns it. Returns ` null ` if document was not found.
8792
8893** Parameters**
8994- filter: [ ` Filter<U> ` ] ( https://mongodb.github.io/node-mongodb-native/4.10/modules.html#Filter ) ;
90- - updateFn : ` (doc: U) => Partial<U> ` ;
95+ - updateFilterOrFn : ` (doc: U) => Partial<U> ` | [ ` UpdateFilter<U> ` ] ( https://mongodb.github.io/node-mongodb-native/4.10/modules.html#UpdateFilter ) ;
9196 Function that accepts current document and returns object containing fields to update.
9297- updateConfig: [ ` UpdateConfig ` ] ( #updateconfig ) ;
9398- updateOptions: [ ` UpdateOptions ` ] ( https://mongodb.github.io/node-mongodb-native/4.10/interfaces/UpdateOptions.html ) ;
@@ -99,7 +104,7 @@ Updates a single document and returns it. Returns `null` if document was not fou
99104``` typescript
100105updateMany = async <U extends T = T >(
101106 filter : Filter <U >,
102- updateFn : (doc : U ) => Partial <U >,
107+ updateFilterOrFn : (doc : U ) => Partial < U > | UpdateFilter <U >,
103108 updateConfig : UpdateConfig = {},
104109 updateOptions : UpdateOptions = {},
105110): Promise < U []>
@@ -110,13 +115,18 @@ const updatedUsers = await userService.updateMany(
110115 { status: ' active' },
111116 (doc ) => ({ isEmailVerified: true }),
112117);
118+
119+ const updatedUsersWithUpdateFilter = await userService .updateMany (
120+ { status: ' active' },
121+ { $set: { isEmailVerified: true } },
122+ );
113123```
114124
115125Updates multiple documents that match the query. Returns array with updated documents.
116126
117127** Parameters**
118128- filter: [ ` Filter<U> ` ] ( https://mongodb.github.io/node-mongodb-native/4.7/modules.html#Filter ) ;
119- - updateFn : ` (doc: U) => Partial<U> ` ;
129+ - updateFilterOrFn : ` (doc: U) => Partial<U> ` | [ ` UpdateFilter<U> ` ] ( https://mongodb.github.io/node-mongodb-native/4.10/modules.html#UpdateFilter ) ;
120130 Function that accepts current document and returns object containing fields to update.
121131- updateConfig: [ ` UpdateConfig ` ] ( #updateconfig ) ;
122132- updateOptions: [ ` UpdateOptions ` ] ( https://mongodb.github.io/node-mongodb-native/4.10/interfaces/UpdateOptions.html ) ;
0 commit comments