Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types(model): fix type of options of Model.aggregate #12933

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion test/types/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
HydratedDocument,
HydratedDocumentFromSchema,
Query,
UpdateWriteOpResult
UpdateWriteOpResult,
AggregateOptions
} from 'mongoose';
import { expectAssignable, expectError, expectType } from 'tsd';
import { AutoTypedSchemaType, autoTypedSchema } from './schema.test';
Expand Down Expand Up @@ -569,3 +570,9 @@ function gh12573ModelAny() {
const { fieldA } = doc;
expectType<any>(fieldA);
}

function aggregateOptionsTest() {
const TestModel = model('test', new Schema({}));
const options: AggregateOptions = {};
TestModel.aggregate(undefined, options);
}
62 changes: 1 addition & 61 deletions types/aggregate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,7 @@ declare module 'mongoose' {
/** Extract generic type from Aggregate class */
type AggregateExtract<P> = P extends Aggregate<infer T> ? T : never;

interface AggregateOptions extends
SessionOption {
/**
* If true, the MongoDB server will use the hard drive to store data during this aggregation.
*/
allowDiskUse?: boolean;
/**
* Applicable only if you specify the $out or $merge aggregation stages.
*
* Enables db.collection.aggregate() to bypass document validation during the operation. This lets you insert documents that do not meet the validation requirements.
*/
bypassDocumentValidation?: boolean;
/**
* The BSON-serializer will check if keys are valid
*/
collation?: mongodb.CollationOptions;
/**
* Users can specify an arbitrary string to help trace the operation through the database profiler, currentOp, and logs.
*/
comment?: string;
/**
* Specifies the initial batch size for the cursor. The value of the cursor field is a document with the field batchSize.
*/
cursor?: { batchSize?: number; };

/**
* Specifies to return the information on the processing of the pipeline. See Return Information on Aggregation Pipeline Operation for an example.
*
* Not available in multi-document transactions.
*/
explain?: mongodb.ExplainVerbosityLike;
/**
* The index to use for the aggregation. The index is on the initial collection/view against which the aggregation is run.
*/
hint?: string | AnyObject;
/**
* Specifies a document with a list of variables. This allows you to improve command readability by separating the variables from the query text.
*/
let?: AnyObject;
/**
* Specifies a time limit in milliseconds for processing operations on a cursor. If you do not specify a value for maxTimeMS, operations will not time out. A value of 0 explicitly specifies the default unbounded behavior.
*
* @see https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/
*/
maxTimeMS?: number;
/**
* Return BSON filled buffers from operations.
*/
raw?: boolean;
/**
* Specifies the read concern.
*/
readConcern?: mongodb.ReadConcernLike;
/**
* The preferred read preference.
*/
readPreference?: mongodb.ReadPreferenceLike;
/**
* Specifies the write concern.
*/
writeConcern?: mongodb.WriteConcern;
interface AggregateOptions extends Omit<mongodb.AggregateOptions, 'session'>, SessionOption {
[key: string]: any;
}

Expand Down
2 changes: 1 addition & 1 deletion types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ declare module 'mongoose' {
>
> & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;

aggregate<R = any>(pipeline?: PipelineStage[], options?: mongodb.AggregateOptions, callback?: Callback<R[]>): Aggregate<Array<R>>;
aggregate<R = any>(pipeline?: PipelineStage[], options?: AggregateOptions, callback?: Callback<R[]>): Aggregate<Array<R>>;
aggregate<R = any>(pipeline: PipelineStage[], callback?: Callback<R[]>): Aggregate<Array<R>>;

/** Base Mongoose instance the model uses. */
Expand Down