Skip to content

Commit a6f619e

Browse files
committed
refactor(NODE-3157): Create separate TS interfaces for individual find and modify type commands
1 parent 9910941 commit a6f619e

File tree

3 files changed

+64
-12
lines changed

3 files changed

+64
-12
lines changed

src/collection.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ import {
4545
FindOneAndDeleteOperation,
4646
FindOneAndReplaceOperation,
4747
FindOneAndUpdateOperation,
48-
FindAndModifyOptions
48+
FindOneAndDeleteOptions,
49+
FindOneAndReplaceOptions,
50+
FindOneAndUpdateOptions
4951
} from './operations/find_and_modify';
5052
import {
5153
InsertOneOperation,
@@ -1103,15 +1105,15 @@ export class Collection {
11031105
*/
11041106
findOneAndDelete(filter: Document): Promise<Document>;
11051107
findOneAndDelete(filter: Document, callback: Callback<Document>): void;
1106-
findOneAndDelete(filter: Document, options: FindAndModifyOptions): Promise<Document>;
1108+
findOneAndDelete(filter: Document, options: FindOneAndDeleteOptions): Promise<Document>;
11071109
findOneAndDelete(
11081110
filter: Document,
1109-
options: FindAndModifyOptions,
1111+
options: FindOneAndDeleteOptions,
11101112
callback: Callback<Document>
11111113
): void;
11121114
findOneAndDelete(
11131115
filter: Document,
1114-
options?: FindAndModifyOptions | Callback<Document>,
1116+
options?: FindOneAndDeleteOptions | Callback<Document>,
11151117
callback?: Callback<Document>
11161118
): Promise<Document> | void {
11171119
if (typeof options === 'function') (callback = options), (options = {});
@@ -1136,18 +1138,18 @@ export class Collection {
11361138
findOneAndReplace(
11371139
filter: Document,
11381140
replacement: Document,
1139-
options: FindAndModifyOptions
1141+
options: FindOneAndReplaceOptions
11401142
): Promise<Document>;
11411143
findOneAndReplace(
11421144
filter: Document,
11431145
replacement: Document,
1144-
options: FindAndModifyOptions,
1146+
options: FindOneAndReplaceOptions,
11451147
callback: Callback<Document>
11461148
): void;
11471149
findOneAndReplace(
11481150
filter: Document,
11491151
replacement: Document,
1150-
options?: FindAndModifyOptions | Callback<Document>,
1152+
options?: FindOneAndReplaceOptions | Callback<Document>,
11511153
callback?: Callback<Document>
11521154
): Promise<Document> | void {
11531155
if (typeof options === 'function') (callback = options), (options = {});
@@ -1172,18 +1174,18 @@ export class Collection {
11721174
findOneAndUpdate(
11731175
filter: Document,
11741176
update: Document,
1175-
options: FindAndModifyOptions
1177+
options: FindOneAndUpdateOptions
11761178
): Promise<Document>;
11771179
findOneAndUpdate(
11781180
filter: Document,
11791181
update: Document,
1180-
options: FindAndModifyOptions,
1182+
options: FindOneAndUpdateOptions,
11811183
callback: Callback<Document>
11821184
): void;
11831185
findOneAndUpdate(
11841186
filter: Document,
11851187
update: Document,
1186-
options?: FindAndModifyOptions | Callback<Document>,
1188+
options?: FindOneAndUpdateOptions | Callback<Document>,
11871189
callback?: Callback<Document>
11881190
): Promise<Document> | void {
11891191
if (typeof options === 'function') (callback = options), (options = {});

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,11 @@ export type { EstimatedDocumentCountOptions } from './operations/estimated_docum
225225
export type { EvalOptions } from './operations/eval';
226226
export type { FindOptions } from './operations/find';
227227
export type { Sort, SortDirection } from './sort';
228-
export type { FindAndModifyOptions } from './operations/find_and_modify';
228+
export type {
229+
FindOneAndDeleteOptions,
230+
FindOneAndReplaceOptions,
231+
FindOneAndUpdateOptions
232+
} from './operations/find_and_modify';
229233
export type {
230234
IndexSpecification,
231235
CreateIndexesOptions,

src/operations/find_and_modify.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,53 @@ import { Sort, formatSort } from '../sort';
1616
import type { ClientSession } from '../sessions';
1717

1818
/** @public */
19-
export interface FindAndModifyOptions extends CommandOperationOptions {
19+
export interface FindOneAndDeleteOptions extends CommandOperationOptions {
20+
/** An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.*/
21+
hint?: Document;
22+
/** Limits the fields to return for all matching documents. */
23+
projection?: Document;
24+
/** Determines which document the operation modifies if the query selects multiple documents. */
25+
sort?: Sort;
26+
}
27+
28+
/** @public */
29+
export interface FindOneAndReplaceOptions extends CommandOperationOptions {
30+
/** Allow driver to bypass schema validation in MongoDB 3.2 or higher. */
31+
bypassDocumentValidation?: boolean;
32+
/** An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.*/
33+
hint?: Document;
34+
/** Limits the fields to return for all matching documents. */
35+
projection?: Document;
36+
/** When false, returns the updated document rather than the original. The default is true. */
37+
returnOriginal?: boolean;
38+
/** Determines which document the operation modifies if the query selects multiple documents. */
39+
sort?: Sort;
40+
/** Upsert the document if it does not exist. */
41+
upsert?: boolean;
42+
}
43+
44+
/** @public */
45+
export interface FindOneAndUpdateOptions extends CommandOperationOptions {
46+
/** Optional list of array filters referenced in filtered positional operators */
47+
arrayFilters?: Document[];
48+
/** Allow driver to bypass schema validation in MongoDB 3.2 or higher. */
49+
bypassDocumentValidation?: boolean;
50+
/** An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.*/
51+
hint?: Document;
52+
/** Limits the fields to return for all matching documents. */
53+
projection?: Document;
54+
/** When false, returns the updated document rather than the original. The default is true. */
55+
returnOriginal?: boolean;
56+
/** Determines which document the operation modifies if the query selects multiple documents. */
57+
sort?: Sort;
58+
/** Upsert the document if it does not exist. */
59+
upsert?: boolean;
60+
}
61+
62+
// TODO: NODE-1812 to deprecate returnOriginal for returnDocument
63+
64+
/** @internal */
65+
interface FindAndModifyOptions extends CommandOperationOptions {
2066
/** When false, returns the updated document rather than the original. The default is true. */
2167
returnOriginal?: boolean;
2268
/** Upsert the document if it does not exist. */

0 commit comments

Comments
 (0)