Skip to content

Commit 1a0180a

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

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,
@@ -1098,15 +1100,15 @@ export class Collection {
10981100
*/
10991101
findOneAndDelete(filter: Document): Promise<Document>;
11001102
findOneAndDelete(filter: Document, callback: Callback<Document>): void;
1101-
findOneAndDelete(filter: Document, options: FindAndModifyOptions): Promise<Document>;
1103+
findOneAndDelete(filter: Document, options: FindOneAndDeleteOptions): Promise<Document>;
11021104
findOneAndDelete(
11031105
filter: Document,
1104-
options: FindAndModifyOptions,
1106+
options: FindOneAndDeleteOptions,
11051107
callback: Callback<Document>
11061108
): void;
11071109
findOneAndDelete(
11081110
filter: Document,
1109-
options?: FindAndModifyOptions | Callback<Document>,
1111+
options?: FindOneAndDeleteOptions | Callback<Document>,
11101112
callback?: Callback<Document>
11111113
): Promise<Document> | void {
11121114
if (typeof options === 'function') (callback = options), (options = {});
@@ -1131,18 +1133,18 @@ export class Collection {
11311133
findOneAndReplace(
11321134
filter: Document,
11331135
replacement: Document,
1134-
options: FindAndModifyOptions
1136+
options: FindOneAndReplaceOptions
11351137
): Promise<Document>;
11361138
findOneAndReplace(
11371139
filter: Document,
11381140
replacement: Document,
1139-
options: FindAndModifyOptions,
1141+
options: FindOneAndReplaceOptions,
11401142
callback: Callback<Document>
11411143
): void;
11421144
findOneAndReplace(
11431145
filter: Document,
11441146
replacement: Document,
1145-
options?: FindAndModifyOptions | Callback<Document>,
1147+
options?: FindOneAndReplaceOptions | Callback<Document>,
11461148
callback?: Callback<Document>
11471149
): Promise<Document> | void {
11481150
if (typeof options === 'function') (callback = options), (options = {});
@@ -1167,18 +1169,18 @@ export class Collection {
11671169
findOneAndUpdate(
11681170
filter: Document,
11691171
update: Document,
1170-
options: FindAndModifyOptions
1172+
options: FindOneAndUpdateOptions
11711173
): Promise<Document>;
11721174
findOneAndUpdate(
11731175
filter: Document,
11741176
update: Document,
1175-
options: FindAndModifyOptions,
1177+
options: FindOneAndUpdateOptions,
11761178
callback: Callback<Document>
11771179
): void;
11781180
findOneAndUpdate(
11791181
filter: Document,
11801182
update: Document,
1181-
options?: FindAndModifyOptions | Callback<Document>,
1183+
options?: FindOneAndUpdateOptions | Callback<Document>,
11821184
callback?: Callback<Document>
11831185
): Promise<Document> | void {
11841186
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)