mongoose 6.2.8 → 6.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +35 -26
- package/CHANGELOG.md +11 -0
- package/dist/browser.umd.js +18 -18
- package/lib/document.js +26 -3
- package/lib/index.js +1 -3
- package/lib/model.js +58 -59
- package/lib/options/SchemaDateOptions.js +8 -1
- package/lib/query.js +39 -2
- package/lib/schematype.js +3 -1
- package/package.json +10 -10
- package/tools/repl.js +8 -8
- package/tools/sharded.js +3 -3
- package/types/connection.d.ts +116 -116
- package/types/error.d.ts +2 -2
- package/types/index.d.ts +63 -61
- package/types/pipelinestage.d.ts +194 -194
- package/types/schemaoptions.d.ts +2 -2
package/types/connection.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import events = require('events');
|
|
|
3
3
|
|
|
4
4
|
declare module 'mongoose' {
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
7
|
* Connection ready state
|
|
8
8
|
*
|
|
9
9
|
* - 0 = disconnected
|
|
@@ -12,147 +12,147 @@ declare module 'mongoose' {
|
|
|
12
12
|
* - 3 = disconnecting
|
|
13
13
|
* - 99 = uninitialized
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
15
|
+
export enum ConnectionStates {
|
|
16
|
+
disconnected = 0,
|
|
17
|
+
connected = 1,
|
|
18
|
+
connecting = 2,
|
|
19
|
+
disconnecting = 3,
|
|
20
|
+
uninitialized = 99,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Expose connection states for user-land */
|
|
24
|
+
export const STATES: typeof ConnectionStates;
|
|
25
|
+
|
|
26
|
+
interface ConnectOptions extends mongodb.MongoClientOptions {
|
|
27
|
+
/** Set to false to [disable buffering](http://mongoosejs.com/docs/faq.html#callback_never_executes) on all models associated with this connection. */
|
|
28
|
+
bufferCommands?: boolean;
|
|
29
|
+
/** The name of the database you want to use. If not provided, Mongoose uses the database name from connection string. */
|
|
30
|
+
dbName?: string;
|
|
31
|
+
/** username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility. */
|
|
32
|
+
user?: string;
|
|
33
|
+
/** password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility. */
|
|
34
|
+
pass?: string;
|
|
35
|
+
/** Set to false to disable automatic index creation for all models associated with this connection. */
|
|
36
|
+
autoIndex?: boolean;
|
|
37
|
+
/** Set to `true` to make Mongoose automatically call `createCollection()` on every model created on this connection. */
|
|
38
|
+
autoCreate?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class Connection extends events.EventEmitter {
|
|
42
|
+
/** Returns a promise that resolves when this connection successfully connects to MongoDB */
|
|
43
|
+
asPromise(): Promise<this>;
|
|
44
|
+
|
|
45
|
+
/** Closes the connection */
|
|
46
|
+
close(force: boolean, callback: CallbackWithoutResult): void;
|
|
47
|
+
close(callback: CallbackWithoutResult): void;
|
|
48
|
+
close(force?: boolean): Promise<void>;
|
|
49
|
+
|
|
50
|
+
/** Retrieves a collection, creating it if not cached. */
|
|
51
|
+
collection<T extends AnyObject = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Collection<T>;
|
|
52
|
+
|
|
53
|
+
/** A hash of the collections associated with this connection */
|
|
54
|
+
readonly collections: { [index: string]: Collection };
|
|
55
|
+
|
|
56
|
+
/** A hash of the global options that are associated with this connection */
|
|
57
|
+
readonly config: any;
|
|
58
|
+
|
|
59
|
+
/** The mongodb.Db instance, set when the connection is opened */
|
|
60
|
+
readonly db: mongodb.Db;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
63
|
* Helper for `createCollection()`. Will explicitly create the given collection
|
|
64
64
|
* with specified options. Used to create [capped collections](https://docs.mongodb.com/manual/core/capped-collections/)
|
|
65
65
|
* and [views](https://docs.mongodb.com/manual/core/views/) from mongoose.
|
|
66
66
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
createCollection<T extends AnyObject = AnyObject>(name: string, options: mongodb.CreateCollectionOptions, callback: Callback<mongodb.Collection<T>>): void;
|
|
68
|
+
createCollection<T extends AnyObject = AnyObject>(name: string, callback: Callback<mongodb.Collection<T>>): void;
|
|
69
|
+
createCollection<T extends AnyObject = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
72
|
* Removes the model named `name` from this connection, if it exists. You can
|
|
73
73
|
* use this function to clean up any models you created in your tests to
|
|
74
74
|
* prevent OverwriteModelErrors.
|
|
75
75
|
*/
|
|
76
|
-
|
|
76
|
+
deleteModel(name: string): this;
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
/**
|
|
79
79
|
* Helper for `dropCollection()`. Will delete the given collection, including
|
|
80
80
|
* all documents and indexes.
|
|
81
81
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
dropCollection(collection: string, callback: CallbackWithoutResult): void;
|
|
83
|
+
dropCollection(collection: string): Promise<void>;
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
/**
|
|
86
86
|
* Helper for `dropDatabase()`. Deletes the given database, including all
|
|
87
87
|
* collections, documents, and indexes.
|
|
88
88
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
dropDatabase(callback: CallbackWithoutResult): void;
|
|
90
|
+
dropDatabase(): Promise<void>;
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
/** Gets the value of the option `key`. */
|
|
93
|
+
get(key: string): any;
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
/**
|
|
96
96
|
* Returns the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
|
|
97
97
|
* that this connection uses to talk to MongoDB.
|
|
98
98
|
*/
|
|
99
|
-
|
|
99
|
+
getClient(): mongodb.MongoClient;
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
/**
|
|
102
102
|
* The host name portion of the URI. If multiple hosts, such as a replica set,
|
|
103
103
|
* this will contain the first host name in the URI
|
|
104
104
|
*/
|
|
105
|
-
|
|
105
|
+
readonly host: string;
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
/**
|
|
108
108
|
* A number identifier for this connection. Used for debugging when
|
|
109
109
|
* you have [multiple connections](/docs/connections.html#multiple_connections).
|
|
110
110
|
*/
|
|
111
|
-
|
|
111
|
+
readonly id: number;
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
/**
|
|
114
114
|
* A [POJO](https://masteringjs.io/tutorials/fundamentals/pojo) containing
|
|
115
115
|
* a map from model names to models. Contains all models that have been
|
|
116
116
|
* added to this connection using [`Connection#model()`](/docs/api/connection.html#connection_Connection-model).
|
|
117
117
|
*/
|
|
118
|
-
|
|
118
|
+
readonly models: Readonly<{ [index: string]: Model<any> }>;
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
/** Defines or retrieves a model. */
|
|
121
|
+
model<T, U, TQueryHelpers = {}>(
|
|
122
|
+
name: string,
|
|
123
|
+
schema?: Schema<T, U, TQueryHelpers>,
|
|
124
|
+
collection?: string,
|
|
125
|
+
options?: CompileModelOptions
|
|
126
|
+
): U;
|
|
127
|
+
model<T>(name: string, schema?: Schema<T>, collection?: string, options?: CompileModelOptions): Model<T>;
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
/** Returns an array of model names created on this connection. */
|
|
130
|
+
modelNames(): Array<string>;
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
/** The name of the database this connection points to. */
|
|
133
|
+
readonly name: string;
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
/** Opens the connection with a URI using `MongoClient.connect()`. */
|
|
136
|
+
openUri(uri: string, options: ConnectOptions, callback: Callback<Connection>): Connection;
|
|
137
|
+
openUri(uri: string, callback: Callback<Connection>): Connection;
|
|
138
|
+
openUri(uri: string, options?: ConnectOptions): Promise<Connection>;
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
/** The password specified in the URI */
|
|
141
|
+
readonly pass: string;
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
/**
|
|
144
144
|
* The port portion of the URI. If multiple hosts, such as a replica set,
|
|
145
145
|
* this will contain the port from the first host name in the URI.
|
|
146
146
|
*/
|
|
147
|
-
|
|
147
|
+
readonly port: number;
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
/** Declares a plugin executed on all schemas you pass to `conn.model()` */
|
|
150
|
+
plugin<S extends Schema = Schema, O = AnyObject>(fn: (schema: S, opts?: any) => void, opts?: O): Connection;
|
|
151
151
|
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
/** The plugins that will be applied to all models created on this connection. */
|
|
153
|
+
plugins: Array<any>;
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
/**
|
|
156
156
|
* Connection ready state
|
|
157
157
|
*
|
|
158
158
|
* - 0 = disconnected
|
|
@@ -161,52 +161,52 @@ declare module 'mongoose' {
|
|
|
161
161
|
* - 3 = disconnecting
|
|
162
162
|
* - 99 = uninitialized
|
|
163
163
|
*/
|
|
164
|
-
|
|
164
|
+
readonly readyState: ConnectionStates;
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
/** Sets the value of the option `key`. */
|
|
167
|
+
set(key: string, value: any): any;
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
/**
|
|
170
170
|
* Set the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
|
|
171
171
|
* that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to
|
|
172
172
|
* reuse it.
|
|
173
173
|
*/
|
|
174
|
-
|
|
174
|
+
setClient(client: mongodb.MongoClient): this;
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
/**
|
|
177
177
|
* _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://docs.mongodb.com/manual/release-notes/3.6/#client-sessions)
|
|
178
178
|
* for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
|
|
179
179
|
* and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
|
|
180
180
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
startSession(options: mongodb.ClientSessionOptions | undefined | null, callback: Callback<mongodb.ClientSession>): void;
|
|
182
|
+
startSession(callback: Callback<mongodb.ClientSession>): void;
|
|
183
|
+
startSession(options?: mongodb.ClientSessionOptions): Promise<mongodb.ClientSession>;
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
/**
|
|
186
186
|
* Makes the indexes in MongoDB match the indexes defined in every model's
|
|
187
187
|
* schema. This function will drop any indexes that are not defined in
|
|
188
188
|
* the model's schema except the `_id` index, and build any indexes that
|
|
189
189
|
* are in your schema but not in MongoDB.
|
|
190
190
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
syncIndexes(options: SyncIndexesOptions | undefined | null, callback: Callback<ConnectionSyncIndexesResult>): void;
|
|
192
|
+
syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
|
|
193
193
|
|
|
194
|
-
|
|
194
|
+
/**
|
|
195
195
|
* _Requires MongoDB >= 3.6.0._ Executes the wrapped async function
|
|
196
196
|
* in a transaction. Mongoose will commit the transaction if the
|
|
197
197
|
* async function executes successfully and attempt to retry if
|
|
198
198
|
* there was a retryable error.
|
|
199
199
|
*/
|
|
200
|
-
|
|
200
|
+
transaction<U = any>(fn: (session: mongodb.ClientSession) => Promise<U>): Promise<U>;
|
|
201
201
|
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
/** Switches to a different database using the same connection pool. */
|
|
203
|
+
useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection;
|
|
204
204
|
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
/** The username specified in the URI */
|
|
206
|
+
readonly user: string;
|
|
207
207
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
/** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model.watch). */
|
|
209
|
+
watch<ResultType = any>(pipeline?: Array<any>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
|
|
210
|
+
}
|
|
211
211
|
|
|
212
212
|
}
|
package/types/error.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import mongodb = require('mongodb');
|
|
|
2
2
|
|
|
3
3
|
declare module 'mongoose' {
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
class NativeError extends global.Error { }
|
|
6
6
|
type CallbackError = NativeError | null;
|
|
7
7
|
|
|
8
8
|
class MongooseError extends global.Error {
|
|
@@ -126,4 +126,4 @@ declare module 'mongoose' {
|
|
|
126
126
|
constructor(doc: Document, currentVersion: number, modifiedPaths: Array<string>);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -178,7 +178,7 @@ declare module 'mongoose' {
|
|
|
178
178
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
179
179
|
interface ClientSession extends mongodb.ClientSession { }
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
/*
|
|
182
182
|
* section collection.js
|
|
183
183
|
* http://mongoosejs.com/docs/api.html#collection-js
|
|
184
184
|
*/
|
|
@@ -231,7 +231,9 @@ declare module 'mongoose' {
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
type AnyKeys<T> = { [P in keyof T]?: T[P] | any };
|
|
234
|
-
interface AnyObject {
|
|
234
|
+
interface AnyObject {
|
|
235
|
+
[k: string]: any
|
|
236
|
+
}
|
|
235
237
|
|
|
236
238
|
type Require_id<T> = T extends { _id?: any } ? (T & { _id: T['_id'] }) : (T & { _id: Types.ObjectId });
|
|
237
239
|
|
|
@@ -906,22 +908,22 @@ declare module 'mongoose' {
|
|
|
906
908
|
type SchemaDefinitionWithBuiltInClass<T> = T extends number
|
|
907
909
|
? NumberSchemaDefinition
|
|
908
910
|
: T extends string
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
911
|
+
? StringSchemaDefinition
|
|
912
|
+
: T extends boolean
|
|
913
|
+
? BooleanSchemaDefinition
|
|
914
|
+
: T extends NativeDate
|
|
915
|
+
? DateSchemaDefinition
|
|
916
|
+
: (Function | string);
|
|
915
917
|
|
|
916
918
|
type SchemaDefinitionProperty<T = undefined> = SchemaDefinitionWithBuiltInClass<T> |
|
|
917
|
-
|
|
919
|
+
SchemaTypeOptions<T extends undefined ? any : T> |
|
|
918
920
|
typeof SchemaType |
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
921
|
+
Schema<any, any, any> |
|
|
922
|
+
Schema<any, any, any>[] |
|
|
923
|
+
SchemaTypeOptions<T extends undefined ? any : Unpacked<T>>[] |
|
|
924
|
+
Function[] |
|
|
925
|
+
SchemaDefinition<T> |
|
|
926
|
+
SchemaDefinition<Unpacked<T>>[] |
|
|
925
927
|
typeof SchemaTypes.Mixed;
|
|
926
928
|
|
|
927
929
|
type SchemaDefinition<T = undefined> = T extends undefined
|
|
@@ -939,20 +941,20 @@ declare module 'mongoose' {
|
|
|
939
941
|
|
|
940
942
|
export class SchemaTypeOptions<T> {
|
|
941
943
|
type?:
|
|
942
|
-
|
|
944
|
+
T extends string ? StringSchemaDefinition :
|
|
943
945
|
T extends number ? NumberSchemaDefinition :
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
946
|
+
T extends boolean ? BooleanSchemaDefinition :
|
|
947
|
+
T extends NativeDate ? DateSchemaDefinition :
|
|
948
|
+
T extends Map<any, any> ? SchemaDefinition<typeof Map> :
|
|
949
|
+
T extends Buffer ? SchemaDefinition<typeof Buffer> :
|
|
950
|
+
T extends Types.ObjectId ? ObjectIdSchemaDefinition :
|
|
951
|
+
T extends Types.ObjectId[] ? AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId>> :
|
|
952
|
+
T extends object[] ? (AnyArray<Schema<any, any, any>> | AnyArray<SchemaDefinition<Unpacked<T>>> | AnyArray<SchemaTypeOptions<Unpacked<T>>>) :
|
|
953
|
+
T extends string[] ? AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string>> :
|
|
954
|
+
T extends number[] ? AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number>> :
|
|
955
|
+
T extends boolean[] ? AnyArray<BooleanSchemaDefinition> | AnyArray<SchemaTypeOptions<boolean>> :
|
|
956
|
+
T extends Function[] ? AnyArray<Function | string> | AnyArray<SchemaTypeOptions<Unpacked<T>>> :
|
|
957
|
+
T | typeof SchemaType | Schema<any, any, any> | SchemaDefinition<T> | Function | AnyArray<Function>;
|
|
956
958
|
|
|
957
959
|
/** Defines a virtual with the given name that gets/sets this path. */
|
|
958
960
|
alias?: string;
|
|
@@ -1097,7 +1099,7 @@ declare module 'mongoose' {
|
|
|
1097
1099
|
export type PopulatedDoc<
|
|
1098
1100
|
PopulatedType,
|
|
1099
1101
|
RawId extends RefType = (PopulatedType extends { _id?: RefType; } ? NonNullable<PopulatedType['_id']> : mongoose.Types.ObjectId) | undefined
|
|
1100
|
-
|
|
1102
|
+
> = PopulatedType | RawId;
|
|
1101
1103
|
|
|
1102
1104
|
interface IndexOptions extends mongodb.CreateIndexesOptions {
|
|
1103
1105
|
/**
|
|
@@ -1465,17 +1467,17 @@ declare module 'mongoose' {
|
|
|
1465
1467
|
}
|
|
1466
1468
|
}
|
|
1467
1469
|
|
|
1468
|
-
type ReturnsNewDoc = { new: true } | { returnOriginal: false } | {returnDocument: 'after'};
|
|
1470
|
+
type ReturnsNewDoc = { new: true } | { returnOriginal: false } | { returnDocument: 'after' };
|
|
1469
1471
|
|
|
1470
1472
|
type QueryWithHelpers<ResultType, DocType, THelpers = {}, RawDocType = DocType> = Query<ResultType, DocType, THelpers, RawDocType> & THelpers;
|
|
1471
1473
|
|
|
1472
|
-
type UnpackedIntersection<T, U> = T extends (infer A)[]
|
|
1474
|
+
type UnpackedIntersection<T, U> = T extends null ? null : T extends (infer A)[]
|
|
1473
1475
|
? (Omit<A, keyof U> & U)[]
|
|
1474
1476
|
: keyof U extends never
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
+
? T
|
|
1478
|
+
: Omit<T, keyof U> & U;
|
|
1477
1479
|
|
|
1478
|
-
type ProjectionFields<DocType> = {[Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: any} & Record<string, any>;
|
|
1480
|
+
type ProjectionFields<DocType> = { [Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: any } & Record<string, any>;
|
|
1479
1481
|
|
|
1480
1482
|
class Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> {
|
|
1481
1483
|
_mongooseOptions: MongooseQueryOptions;
|
|
@@ -1774,8 +1776,8 @@ declare module 'mongoose' {
|
|
|
1774
1776
|
polygon(path: string, ...coordinatePairs: number[][]): this;
|
|
1775
1777
|
|
|
1776
1778
|
/** Specifies paths which should be populated with other documents. */
|
|
1777
|
-
populate<Paths = {}>(path: string | string[], select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType
|
|
1778
|
-
populate<Paths = {}>(options: PopulateOptions | (PopulateOptions | string)[]): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType
|
|
1779
|
+
populate<Paths = {}>(path: string | string[], select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, UnpackedIntersection<RawDocType, Paths>>;
|
|
1780
|
+
populate<Paths = {}>(options: PopulateOptions | (PopulateOptions | string)[]): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, UnpackedIntersection<RawDocType, Paths>>;
|
|
1779
1781
|
|
|
1780
1782
|
/** Get/set the current projection (AKA fields). Pass `null` to remove the current projection. */
|
|
1781
1783
|
projection(): ProjectionFields<DocType> | null;
|
|
@@ -1965,10 +1967,10 @@ declare module 'mongoose' {
|
|
|
1965
1967
|
$or?: Array<FilterQuery<T>>;
|
|
1966
1968
|
/** @see https://docs.mongodb.com/manual/reference/operator/query/text */
|
|
1967
1969
|
$text?: {
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1970
|
+
$search: string;
|
|
1971
|
+
$language?: string;
|
|
1972
|
+
$caseSensitive?: boolean;
|
|
1973
|
+
$diacriticSensitive?: boolean;
|
|
1972
1974
|
};
|
|
1973
1975
|
/** @see https://docs.mongodb.com/manual/reference/operator/query/where/#op._S_where */
|
|
1974
1976
|
$where?: string | Function;
|
|
@@ -1985,7 +1987,7 @@ declare module 'mongoose' {
|
|
|
1985
1987
|
type _FilterQuery<T> = {
|
|
1986
1988
|
[P in keyof T]?: Condition<T[P]>;
|
|
1987
1989
|
} &
|
|
1988
|
-
|
|
1990
|
+
RootQuerySelector<T>;
|
|
1989
1991
|
|
|
1990
1992
|
/**
|
|
1991
1993
|
* Filter query to select the documents that match the query
|
|
@@ -2032,21 +2034,21 @@ declare module 'mongoose' {
|
|
|
2032
2034
|
|
|
2033
2035
|
/** @see https://docs.mongodb.com/manual/reference/operator/update-bitwise/ */
|
|
2034
2036
|
$bit?: {
|
|
2035
|
-
|
|
2037
|
+
[key: string]: { [key in 'and' | 'or' | 'xor']?: number };
|
|
2036
2038
|
};
|
|
2037
2039
|
};
|
|
2038
2040
|
|
|
2039
2041
|
type UpdateWithAggregationPipeline = UpdateAggregationStage[];
|
|
2040
2042
|
type UpdateAggregationStage = { $addFields: any } |
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2043
|
+
{ $set: any } |
|
|
2044
|
+
{ $project: any } |
|
|
2045
|
+
{ $unset: any } |
|
|
2046
|
+
{ $replaceRoot: any } |
|
|
2047
|
+
{ $replaceWith: any };
|
|
2046
2048
|
|
|
2047
2049
|
type __UpdateDefProperty<T> =
|
|
2048
2050
|
[Extract<T, mongodb.ObjectId>] extends [never] ? T :
|
|
2049
|
-
|
|
2051
|
+
T | string;
|
|
2050
2052
|
type _UpdateQueryDef<T> = {
|
|
2051
2053
|
[K in keyof T]?: __UpdateDefProperty<T[K]>;
|
|
2052
2054
|
};
|
|
@@ -2062,28 +2064,28 @@ declare module 'mongoose' {
|
|
|
2062
2064
|
|
|
2063
2065
|
export type DocumentDefinition<T> = {
|
|
2064
2066
|
[K in keyof Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>>]:
|
|
2065
|
-
|
|
2067
|
+
[Extract<T[K], mongodb.ObjectId>] extends [never]
|
|
2066
2068
|
? T[K] extends TreatAsPrimitives
|
|
2067
2069
|
? T[K]
|
|
2068
2070
|
: LeanDocumentElement<T[K]>
|
|
2069
2071
|
: T[K] | string;
|
|
2070
|
-
|
|
2072
|
+
};
|
|
2071
2073
|
|
|
2072
2074
|
export type FlattenMaps<T> = {
|
|
2073
2075
|
[K in keyof T]: T[K] extends Map<any, any>
|
|
2074
2076
|
? AnyObject : T[K] extends TreatAsPrimitives
|
|
2075
|
-
|
|
2077
|
+
? T[K] : FlattenMaps<T[K]>;
|
|
2076
2078
|
};
|
|
2077
2079
|
|
|
2078
2080
|
type actualPrimitives = string | boolean | number | bigint | symbol | null | undefined;
|
|
2079
2081
|
type TreatAsPrimitives = actualPrimitives |
|
|
2080
|
-
|
|
2082
|
+
NativeDate | RegExp | symbol | Error | BigInt | Types.ObjectId;
|
|
2081
2083
|
|
|
2082
2084
|
type LeanType<T> =
|
|
2083
2085
|
0 extends (1 & T) ? T : // any
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2086
|
+
T extends TreatAsPrimitives ? T : // primitives
|
|
2087
|
+
T extends Types.Subdocument ? Omit<LeanDocument<T>, '$isSingleNested' | 'ownerDocument' | 'parent'> : // subdocs
|
|
2088
|
+
LeanDocument<T>; // Documents and everything else
|
|
2087
2089
|
|
|
2088
2090
|
type LeanArray<T extends unknown[]> = T extends unknown[][] ? LeanArray<T[number]>[] : LeanType<T[number]>[];
|
|
2089
2091
|
|
|
@@ -2096,8 +2098,8 @@ declare module 'mongoose' {
|
|
|
2096
2098
|
// This is required for PopulatedDoc.
|
|
2097
2099
|
type LeanDocumentElement<T> =
|
|
2098
2100
|
T extends unknown[] ? LeanArray<T> : // Array
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
+
T extends Document ? LeanDocument<T> : // Subdocument
|
|
2102
|
+
T;
|
|
2101
2103
|
|
|
2102
2104
|
export type SchemaDefinitionType<T> = T extends Document ? Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>> : T;
|
|
2103
2105
|
|
|
@@ -2110,13 +2112,13 @@ declare module 'mongoose' {
|
|
|
2110
2112
|
|
|
2111
2113
|
export type LeanDocumentOrArray<T> = 0 extends (1 & T) ? T :
|
|
2112
2114
|
T extends unknown[] ? LeanDocument<T[number]>[] :
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
+
T extends Document ? LeanDocument<T> :
|
|
2116
|
+
T;
|
|
2115
2117
|
|
|
2116
2118
|
export type LeanDocumentOrArrayWithRawType<T, RawDocType> = 0 extends (1 & T) ? T :
|
|
2117
2119
|
T extends unknown[] ? RawDocType[] :
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
+
T extends Document ? RawDocType :
|
|
2121
|
+
T;
|
|
2120
2122
|
|
|
2121
2123
|
class Aggregate<R> {
|
|
2122
2124
|
/**
|