mongoose 5.12.1 → 5.12.2
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/History.md +14 -0
- package/dist/browser.umd.js +27 -27
- package/index.d.ts +47 -37
- package/lib/browser.js +8 -5
- package/lib/cursor/QueryCursor.js +2 -2
- package/lib/document.js +0 -1
- package/lib/helpers/model/castBulkWrite.js +3 -3
- package/lib/index.js +8 -5
- package/lib/queryhelpers.js +5 -1
- package/lib/schema/array.js +4 -0
- package/lib/schema.js +5 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -848,13 +848,13 @@ declare module 'mongoose' {
|
|
|
848
848
|
* @deprecated use `updateOne` or `updateMany` instead.
|
|
849
849
|
* Creates a `update` query: updates one or many documents that match `filter` with `update`, based on the `multi` option.
|
|
850
850
|
*/
|
|
851
|
-
update(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: any, res: any) => void): QueryWithHelpers<
|
|
851
|
+
update(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: any, res: any) => void): QueryWithHelpers<UpdateWriteOpResult, T, TQueryHelpers>;
|
|
852
852
|
|
|
853
853
|
/** Creates a `updateMany` query: updates all documents that match `filter` with `update`. */
|
|
854
|
-
updateMany(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: any, res: any) => void): QueryWithHelpers<
|
|
854
|
+
updateMany(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: any, res: any) => void): QueryWithHelpers<UpdateWriteOpResult, T, TQueryHelpers>;
|
|
855
855
|
|
|
856
856
|
/** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */
|
|
857
|
-
updateOne(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: any, res: any) => void): QueryWithHelpers<
|
|
857
|
+
updateOne(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: any, res: any) => void): QueryWithHelpers<UpdateWriteOpResult, T, TQueryHelpers>;
|
|
858
858
|
|
|
859
859
|
/** Creates a Query, applies the passed conditions, and returns the Query. */
|
|
860
860
|
where(path: string, val?: any): QueryWithHelpers<Array<T>, T, TQueryHelpers>;
|
|
@@ -862,6 +862,11 @@ declare module 'mongoose' {
|
|
|
862
862
|
where(): QueryWithHelpers<Array<T>, T, TQueryHelpers>;
|
|
863
863
|
}
|
|
864
864
|
|
|
865
|
+
type _UpdateWriteOpResult = mongodb.UpdateWriteOpResult['result'];
|
|
866
|
+
interface UpdateWriteOpResult extends _UpdateWriteOpResult {
|
|
867
|
+
upserted?: Array<{index: number, _id: any}>;
|
|
868
|
+
}
|
|
869
|
+
|
|
865
870
|
interface QueryOptions {
|
|
866
871
|
arrayFilters?: { [key: string]: any }[];
|
|
867
872
|
batchSize?: number;
|
|
@@ -1059,6 +1064,8 @@ declare module 'mongoose' {
|
|
|
1059
1064
|
type SchemaPreOptions = { document?: boolean, query?: boolean };
|
|
1060
1065
|
type SchemaPostOptions = { document?: boolean, query?: boolean };
|
|
1061
1066
|
|
|
1067
|
+
type ExtractQueryHelpers<M> = M extends Model<any, infer TQueryHelpers> ? TQueryHelpers : {};
|
|
1068
|
+
|
|
1062
1069
|
class Schema<DocType extends Document = Document, M extends Model<DocType, any> = Model<any, any>, SchemaDefinitionType = undefined> extends events.EventEmitter {
|
|
1063
1070
|
/**
|
|
1064
1071
|
* Create a new schema
|
|
@@ -1162,7 +1169,7 @@ declare module 'mongoose' {
|
|
|
1162
1169
|
pre<T extends Model<DocType> = M>(method: 'insertMany' | RegExp, options: SchemaPreOptions, fn: (this: T, next: (err: CallbackError) => void) => void): this;
|
|
1163
1170
|
|
|
1164
1171
|
/** Object of currently defined query helpers on this schema. */
|
|
1165
|
-
query: { [name: string]: <T extends
|
|
1172
|
+
query: { [name: string]: <T extends QueryWithHelpers<any, DocType, ExtractQueryHelpers<M>> = QueryWithHelpers<any, DocType, ExtractQueryHelpers<M>>>(this: T, ...args: any[]) => any };
|
|
1166
1173
|
|
|
1167
1174
|
/** Adds a method call to the queue. */
|
|
1168
1175
|
queue(name: string, args: any[]): this;
|
|
@@ -1383,9 +1390,9 @@ declare module 'mongoose' {
|
|
|
1383
1390
|
export class SchemaTypeOptions<T> {
|
|
1384
1391
|
type?:
|
|
1385
1392
|
T extends string | number | Function ? SchemaDefinitionWithBuiltInClass<T> :
|
|
1386
|
-
T extends Schema
|
|
1393
|
+
T extends Schema ? T :
|
|
1387
1394
|
T extends object[] ? Schema<Document<Unpacked<T>>>[] :
|
|
1388
|
-
T;
|
|
1395
|
+
T | typeof SchemaType | Schema;
|
|
1389
1396
|
|
|
1390
1397
|
/** Defines a virtual with the given name that gets/sets this path. */
|
|
1391
1398
|
alias?: string;
|
|
@@ -1847,7 +1854,7 @@ declare module 'mongoose' {
|
|
|
1847
1854
|
exec(callback?: (err: any, result: ResultType) => void): Promise<ResultType> | any;
|
|
1848
1855
|
|
|
1849
1856
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
1850
|
-
$where(argument: string | Function):
|
|
1857
|
+
$where(argument: string | Function): QueryWithHelpers<DocType[], DocType, THelpers>;
|
|
1851
1858
|
|
|
1852
1859
|
/** Specifies an `$all` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
1853
1860
|
all(val: Array<any>): this;
|
|
@@ -1883,12 +1890,12 @@ declare module 'mongoose' {
|
|
|
1883
1890
|
comment(val: string): this;
|
|
1884
1891
|
|
|
1885
1892
|
/** Specifies this query as a `count` query. */
|
|
1886
|
-
count(callback?: (err: any, count: number) => void):
|
|
1887
|
-
count(criteria: FilterQuery<DocType>, callback?: (err: any, count: number) => void):
|
|
1893
|
+
count(callback?: (err: any, count: number) => void): QueryWithHelpers<number, DocType, THelpers>;
|
|
1894
|
+
count(criteria: FilterQuery<DocType>, callback?: (err: any, count: number) => void): QueryWithHelpers<number, DocType, THelpers>;
|
|
1888
1895
|
|
|
1889
1896
|
/** Specifies this query as a `countDocuments` query. */
|
|
1890
|
-
countDocuments(callback?: (err: any, count: number) => void):
|
|
1891
|
-
countDocuments(criteria: FilterQuery<DocType>, callback?: (err: any, count: number) => void):
|
|
1897
|
+
countDocuments(callback?: (err: any, count: number) => void): QueryWithHelpers<number, DocType, THelpers>;
|
|
1898
|
+
countDocuments(criteria: FilterQuery<DocType>, callback?: (err: any, count: number) => void): QueryWithHelpers<number, DocType, THelpers>;
|
|
1892
1899
|
|
|
1893
1900
|
/**
|
|
1894
1901
|
* Returns a wrapper around a [mongodb driver cursor](http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html).
|
|
@@ -1901,17 +1908,17 @@ declare module 'mongoose' {
|
|
|
1901
1908
|
* remove, except it deletes _every_ document that matches `filter` in the
|
|
1902
1909
|
* collection, regardless of the value of `single`.
|
|
1903
1910
|
*/
|
|
1904
|
-
deleteMany(filter?: FilterQuery<DocType>, options?: QueryOptions, callback?: (err: CallbackError, res: any) => void):
|
|
1911
|
+
deleteMany(filter?: FilterQuery<DocType>, options?: QueryOptions, callback?: (err: CallbackError, res: any) => void): QueryWithHelpers<any, DocType, THelpers>;
|
|
1905
1912
|
|
|
1906
1913
|
/**
|
|
1907
1914
|
* Declare and/or execute this query as a `deleteOne()` operation. Works like
|
|
1908
1915
|
* remove, except it deletes at most one document regardless of the `single`
|
|
1909
1916
|
* option.
|
|
1910
1917
|
*/
|
|
1911
|
-
deleteOne(filter?: FilterQuery<DocType>, options?: QueryOptions, callback?: (err: CallbackError, res: any) => void):
|
|
1918
|
+
deleteOne(filter?: FilterQuery<DocType>, options?: QueryOptions, callback?: (err: CallbackError, res: any) => void): QueryWithHelpers<any, DocType, THelpers>;
|
|
1912
1919
|
|
|
1913
1920
|
/** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */
|
|
1914
|
-
distinct(field: string, filter?: FilterQuery<DocType>, callback?: (err: any, count: number) => void):
|
|
1921
|
+
distinct(field: string, filter?: FilterQuery<DocType>, callback?: (err: any, count: number) => void): QueryWithHelpers<Array<any>, DocType, THelpers>;
|
|
1915
1922
|
|
|
1916
1923
|
/** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
1917
1924
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -1930,7 +1937,7 @@ declare module 'mongoose' {
|
|
|
1930
1937
|
equals(val: any): this;
|
|
1931
1938
|
|
|
1932
1939
|
/** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */
|
|
1933
|
-
estimatedDocumentCount(options?: QueryOptions, callback?: (err: any, count: number) => void):
|
|
1940
|
+
estimatedDocumentCount(options?: QueryOptions, callback?: (err: any, count: number) => void): QueryWithHelpers<number, DocType, THelpers>;
|
|
1934
1941
|
|
|
1935
1942
|
/** Specifies a `$exists` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
1936
1943
|
exists(val: boolean): this;
|
|
@@ -1945,31 +1952,31 @@ declare module 'mongoose' {
|
|
|
1945
1952
|
explain(verbose?: string): this;
|
|
1946
1953
|
|
|
1947
1954
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
1948
|
-
find(callback?: (err: any, docs: DocType[]) => void):
|
|
1949
|
-
find(filter: FilterQuery<DocType>, callback?: (err: any, docs: DocType[]) => void):
|
|
1950
|
-
find(filter: FilterQuery<DocType>, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError, docs: DocType[]) => void):
|
|
1955
|
+
find(callback?: (err: any, docs: DocType[]) => void): QueryWithHelpers<Array<DocType>, DocType, THelpers>;
|
|
1956
|
+
find(filter: FilterQuery<DocType>, callback?: (err: any, docs: DocType[]) => void): QueryWithHelpers<Array<DocType>, DocType, THelpers>;
|
|
1957
|
+
find(filter: FilterQuery<DocType>, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError, docs: DocType[]) => void): QueryWithHelpers<Array<DocType>, DocType, THelpers>;
|
|
1951
1958
|
|
|
1952
1959
|
/** Declares the query a findOne operation. When executed, the first found document is passed to the callback. */
|
|
1953
|
-
findOne(filter?: FilterQuery<DocType>, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError, doc: DocType | null) => void):
|
|
1960
|
+
findOne(filter?: FilterQuery<DocType>, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError, doc: DocType | null) => void): QueryWithHelpers<DocType | null, DocType, THelpers>;
|
|
1954
1961
|
|
|
1955
1962
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
1956
|
-
findOneAndDelete(filter?: FilterQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void):
|
|
1963
|
+
findOneAndDelete(filter?: FilterQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers>;
|
|
1957
1964
|
|
|
1958
1965
|
/** Creates a `findOneAndRemove` query: atomically finds the given document and deletes it. */
|
|
1959
|
-
findOneAndRemove(filter?: FilterQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void):
|
|
1966
|
+
findOneAndRemove(filter?: FilterQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers>;
|
|
1960
1967
|
|
|
1961
1968
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
1962
|
-
findOneAndUpdate(filter: FilterQuery<DocType>, update: UpdateQuery<DocType>, options: QueryOptions & { rawResult: true }, callback?: (err: any, doc: mongodb.FindAndModifyWriteOpResultObject<DocType>, res: any) => void):
|
|
1963
|
-
findOneAndUpdate(filter: FilterQuery<DocType>, update: UpdateQuery<DocType>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: any, doc: DocType, res: any) => void):
|
|
1964
|
-
findOneAndUpdate(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void):
|
|
1969
|
+
findOneAndUpdate(filter: FilterQuery<DocType>, update: UpdateQuery<DocType>, options: QueryOptions & { rawResult: true }, callback?: (err: any, doc: mongodb.FindAndModifyWriteOpResultObject<DocType>, res: any) => void): QueryWithHelpers<mongodb.FindAndModifyWriteOpResultObject<DocType>, DocType, THelpers>;
|
|
1970
|
+
findOneAndUpdate(filter: FilterQuery<DocType>, update: UpdateQuery<DocType>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: any, doc: DocType, res: any) => void): QueryWithHelpers<DocType, DocType, THelpers>;
|
|
1971
|
+
findOneAndUpdate(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers>;
|
|
1965
1972
|
|
|
1966
1973
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
1967
|
-
findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void):
|
|
1974
|
+
findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers>;
|
|
1968
1975
|
|
|
1969
1976
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
1970
|
-
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions & { rawResult: true }, callback?: (err: any, doc: mongodb.FindAndModifyWriteOpResultObject<DocType>, res: any) => void):
|
|
1971
|
-
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: any, doc: DocType, res: any) => void):
|
|
1972
|
-
findByIdAndUpdate(id?: mongodb.ObjectId | any, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void):
|
|
1977
|
+
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions & { rawResult: true }, callback?: (err: any, doc: mongodb.FindAndModifyWriteOpResultObject<DocType>, res: any) => void): QueryWithHelpers<mongodb.FindAndModifyWriteOpResultObject<DocType>, DocType, THelpers>;
|
|
1978
|
+
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions & { upsert: true } & ReturnsNewDoc, callback?: (err: any, doc: DocType, res: any) => void): QueryWithHelpers<DocType, DocType, THelpers>;
|
|
1979
|
+
findByIdAndUpdate(id?: mongodb.ObjectId | any, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): QueryWithHelpers<DocType | null, DocType, THelpers>;
|
|
1973
1980
|
|
|
1974
1981
|
/** Specifies a `$geometry` condition */
|
|
1975
1982
|
geometry(object: { type: string, coordinates: any[] }): this;
|
|
@@ -2018,7 +2025,7 @@ declare module 'mongoose' {
|
|
|
2018
2025
|
j(val: boolean | null): this;
|
|
2019
2026
|
|
|
2020
2027
|
/** Sets the lean option. */
|
|
2021
|
-
lean<LeanResultType = LeanDocumentOrArray<ResultType>>(val?: boolean | any):
|
|
2028
|
+
lean<LeanResultType = LeanDocumentOrArray<ResultType>>(val?: boolean | any): QueryWithHelpers<LeanResultType, DocType, THelpers>;
|
|
2022
2029
|
|
|
2023
2030
|
/** Specifies the maximum number of documents the query will return. */
|
|
2024
2031
|
limit(val: number): this;
|
|
@@ -2035,7 +2042,7 @@ declare module 'mongoose' {
|
|
|
2035
2042
|
* Runs a function `fn` and treats the return value of `fn` as the new value
|
|
2036
2043
|
* for the query to resolve to.
|
|
2037
2044
|
*/
|
|
2038
|
-
map<MappedType>(fn: (doc: DocType) => MappedType):
|
|
2045
|
+
map<MappedType>(fn: (doc: DocType) => MappedType): QueryWithHelpers<MappedType, DocType, THelpers>;
|
|
2039
2046
|
|
|
2040
2047
|
/** Specifies an `$maxDistance` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
2041
2048
|
maxDistance(val: number): this;
|
|
@@ -2087,7 +2094,7 @@ declare module 'mongoose' {
|
|
|
2087
2094
|
* This is handy for integrating with async/await, because `orFail()` saves you
|
|
2088
2095
|
* an extra `if` statement to check if no document was found.
|
|
2089
2096
|
*/
|
|
2090
|
-
orFail(err?: NativeError | (() => NativeError)):
|
|
2097
|
+
orFail(err?: NativeError | (() => NativeError)): QueryWithHelpers<NonNullable<ResultType>, DocType, THelpers>;
|
|
2091
2098
|
|
|
2092
2099
|
/** Specifies a `$polygon` condition */
|
|
2093
2100
|
polygon(...coordinatePairs: number[][]): this;
|
|
@@ -2115,14 +2122,14 @@ declare module 'mongoose' {
|
|
|
2115
2122
|
* deprecated, you should use [`deleteOne()`](#query_Query-deleteOne)
|
|
2116
2123
|
* or [`deleteMany()`](#query_Query-deleteMany) instead.
|
|
2117
2124
|
*/
|
|
2118
|
-
remove(filter?: FilterQuery<DocType>, callback?: (err: CallbackError, res: mongodb.WriteOpResult['result']) => void):
|
|
2125
|
+
remove(filter?: FilterQuery<DocType>, callback?: (err: CallbackError, res: mongodb.WriteOpResult['result']) => void): QueryWithHelpers<mongodb.WriteOpResult['result'], DocType, THelpers>;
|
|
2119
2126
|
|
|
2120
2127
|
/**
|
|
2121
2128
|
* Declare and/or execute this query as a replaceOne() operation. Same as
|
|
2122
2129
|
* `update()`, except MongoDB will replace the existing document and will
|
|
2123
2130
|
* not accept any [atomic](https://docs.mongodb.com/manual/tutorial/model-data-for-atomic-operations/#pattern) operators (`$set`, etc.)
|
|
2124
2131
|
*/
|
|
2125
|
-
replaceOne(filter?: FilterQuery<DocType>, replacement?: DocumentDefinition<DocType>, options?: QueryOptions | null, callback?: (err: any, res: any) => void):
|
|
2132
|
+
replaceOne(filter?: FilterQuery<DocType>, replacement?: DocumentDefinition<DocType>, options?: QueryOptions | null, callback?: (err: any, res: any) => void): QueryWithHelpers<any, DocType, THelpers>;
|
|
2126
2133
|
|
|
2127
2134
|
/** Specifies which document fields to include or exclude (also known as the query "projection") */
|
|
2128
2135
|
select(arg: string | any): this;
|
|
@@ -2188,10 +2195,10 @@ declare module 'mongoose' {
|
|
|
2188
2195
|
then: Promise<ResultType>['then'];
|
|
2189
2196
|
|
|
2190
2197
|
/** Converts this query to a customized, reusable query constructor with all arguments and options retained. */
|
|
2191
|
-
toConstructor(): new (...args: any[]) =>
|
|
2198
|
+
toConstructor(): new (...args: any[]) => QueryWithHelpers<ResultType, DocType, THelpers>;
|
|
2192
2199
|
|
|
2193
2200
|
/** Declare and/or execute this query as an update() operation. */
|
|
2194
|
-
update(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: CallbackError, res:
|
|
2201
|
+
update(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: CallbackError, res: UpdateWriteOpResult) => void): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers>;
|
|
2195
2202
|
|
|
2196
2203
|
/**
|
|
2197
2204
|
* Declare and/or execute this query as an updateMany() operation. Same as
|
|
@@ -2199,13 +2206,13 @@ declare module 'mongoose' {
|
|
|
2199
2206
|
* `filter` (as opposed to just the first one) regardless of the value of
|
|
2200
2207
|
* the `multi` option.
|
|
2201
2208
|
*/
|
|
2202
|
-
updateMany(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: CallbackError, res:
|
|
2209
|
+
updateMany(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: CallbackError, res: UpdateWriteOpResult) => void): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers>;
|
|
2203
2210
|
|
|
2204
2211
|
/**
|
|
2205
2212
|
* Declare and/or execute this query as an updateOne() operation. Same as
|
|
2206
2213
|
* `update()`, except it does not support the `multi` or `overwrite` options.
|
|
2207
2214
|
*/
|
|
2208
|
-
updateOne(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: CallbackError, res:
|
|
2215
|
+
updateOne(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: CallbackError, res: UpdateWriteOpResult) => void): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers>;
|
|
2209
2216
|
|
|
2210
2217
|
/**
|
|
2211
2218
|
* Sets the specified number of `mongod` servers, or tag set of `mongod` servers,
|
|
@@ -2434,6 +2441,9 @@ declare module 'mongoose' {
|
|
|
2434
2441
|
/** Returns the current pipeline */
|
|
2435
2442
|
pipeline(): any[];
|
|
2436
2443
|
|
|
2444
|
+
/** Appends a new $project operator to this aggregate pipeline. */
|
|
2445
|
+
project(arg: string | Object): this;
|
|
2446
|
+
|
|
2437
2447
|
/** Sets the readPreference option for the aggregation query. */
|
|
2438
2448
|
read(pref: string | mongodb.ReadPreferenceMode, tags?: any[]): this;
|
|
2439
2449
|
|
package/lib/browser.js
CHANGED
|
@@ -68,11 +68,14 @@ exports.Schema = require('./schema');
|
|
|
68
68
|
*
|
|
69
69
|
* ####Types:
|
|
70
70
|
*
|
|
71
|
-
* - [
|
|
72
|
-
* - [Buffer](#
|
|
73
|
-
* - [
|
|
74
|
-
* - [
|
|
75
|
-
* - [
|
|
71
|
+
* - [Array](/docs/schematypes.html#arrays)
|
|
72
|
+
* - [Buffer](/docs/schematypes.html#buffers)
|
|
73
|
+
* - [Embedded](/docs/schematypes.html#schemas)
|
|
74
|
+
* - [DocumentArray](/docs/api/documentarraypath.html)
|
|
75
|
+
* - [Decimal128](/docs/api.html#mongoose_Mongoose-Decimal128)
|
|
76
|
+
* - [ObjectId](/docs/schematypes.html#objectids)
|
|
77
|
+
* - [Map](/docs/schematypes.html#maps)
|
|
78
|
+
* - [Subdocument](/docs/schematypes.html#schemas)
|
|
76
79
|
*
|
|
77
80
|
* Using this exposed access to the `ObjectId` type, we can construct ids on demand.
|
|
78
81
|
*
|
|
@@ -441,7 +441,7 @@ function _populateBatch() {
|
|
|
441
441
|
|
|
442
442
|
function _nextDoc(ctx, doc, pop, callback) {
|
|
443
443
|
if (ctx.query._mongooseOptions.lean) {
|
|
444
|
-
return ctx.model.hooks.execPost('find', ctx.query, [doc], err => {
|
|
444
|
+
return ctx.model.hooks.execPost('find', ctx.query, [[doc]], err => {
|
|
445
445
|
if (err != null) {
|
|
446
446
|
return callback(err);
|
|
447
447
|
}
|
|
@@ -453,7 +453,7 @@ function _nextDoc(ctx, doc, pop, callback) {
|
|
|
453
453
|
if (err != null) {
|
|
454
454
|
return callback(err);
|
|
455
455
|
}
|
|
456
|
-
ctx.model.hooks.execPost('find', ctx.query, [doc], err => {
|
|
456
|
+
ctx.model.hooks.execPost('find', ctx.query, [[doc]], err => {
|
|
457
457
|
if (err != null) {
|
|
458
458
|
return callback(err);
|
|
459
459
|
}
|
package/lib/document.js
CHANGED
|
@@ -20,7 +20,7 @@ module.exports = function castBulkWrite(originalModel, op, options) {
|
|
|
20
20
|
const model = decideModelByObject(originalModel, op['insertOne']['document']);
|
|
21
21
|
|
|
22
22
|
const doc = new model(op['insertOne']['document']);
|
|
23
|
-
if (model.schema.options.timestamps
|
|
23
|
+
if (model.schema.options.timestamps) {
|
|
24
24
|
doc.initializeTimestamps();
|
|
25
25
|
}
|
|
26
26
|
if (options.session != null) {
|
|
@@ -147,7 +147,7 @@ module.exports = function castBulkWrite(originalModel, op, options) {
|
|
|
147
147
|
|
|
148
148
|
// set `skipId`, otherwise we get "_id field cannot be changed"
|
|
149
149
|
const doc = new model(op['replaceOne']['replacement'], strict, true);
|
|
150
|
-
if (model.schema.options.timestamps
|
|
150
|
+
if (model.schema.options.timestamps) {
|
|
151
151
|
doc.initializeTimestamps();
|
|
152
152
|
}
|
|
153
153
|
if (options.session != null) {
|
|
@@ -221,4 +221,4 @@ function decideModelByObject(model, object) {
|
|
|
221
221
|
model = getDiscriminatorByValue(model, object[discriminatorKey]) || model;
|
|
222
222
|
}
|
|
223
223
|
return model;
|
|
224
|
-
}
|
|
224
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -866,11 +866,14 @@ Mongoose.prototype.VirtualType = VirtualType;
|
|
|
866
866
|
*
|
|
867
867
|
* ####Types:
|
|
868
868
|
*
|
|
869
|
-
* - [
|
|
870
|
-
* - [Buffer](#
|
|
871
|
-
* - [
|
|
872
|
-
* - [
|
|
873
|
-
* - [
|
|
869
|
+
* - [Array](/docs/schematypes.html#arrays)
|
|
870
|
+
* - [Buffer](/docs/schematypes.html#buffers)
|
|
871
|
+
* - [Embedded](/docs/schematypes.html#schemas)
|
|
872
|
+
* - [DocumentArray](/docs/api/documentarraypath.html)
|
|
873
|
+
* - [Decimal128](/docs/api.html#mongoose_Mongoose-Decimal128)
|
|
874
|
+
* - [ObjectId](/docs/schematypes.html#objectids)
|
|
875
|
+
* - [Map](/docs/schematypes.html#maps)
|
|
876
|
+
* - [Subdocument](/docs/schematypes.html#schemas)
|
|
874
877
|
*
|
|
875
878
|
* Using this exposed access to the `ObjectId` type, we can construct ids on demand.
|
|
876
879
|
*
|
package/lib/queryhelpers.js
CHANGED
|
@@ -199,7 +199,11 @@ exports.applyPaths = function applyPaths(fields, schema) {
|
|
|
199
199
|
schema.eachPath(function(path, type) {
|
|
200
200
|
if (prefix) path = prefix + '.' + path;
|
|
201
201
|
|
|
202
|
-
|
|
202
|
+
let addedPath = analyzePath(path, type);
|
|
203
|
+
// arrays
|
|
204
|
+
if (addedPath == null && type.$isMongooseArray && !type.$isMongooseDocumentArray) {
|
|
205
|
+
addedPath = analyzePath(path, type.caster);
|
|
206
|
+
}
|
|
203
207
|
if (addedPath != null) {
|
|
204
208
|
addedPaths.push(addedPath);
|
|
205
209
|
}
|
package/lib/schema/array.js
CHANGED
package/lib/schema.js
CHANGED
|
@@ -466,6 +466,11 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
466
466
|
}
|
|
467
467
|
|
|
468
468
|
prefix = prefix || '';
|
|
469
|
+
// avoid prototype pollution
|
|
470
|
+
if (prefix === '__proto__.' || prefix === 'constructor.' || prefix === 'prototype.') {
|
|
471
|
+
return this;
|
|
472
|
+
}
|
|
473
|
+
|
|
469
474
|
const keys = Object.keys(obj);
|
|
470
475
|
|
|
471
476
|
for (const key of keys) {
|