mongoose 9.2.2 → 9.2.4
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/lib/aggregate.js +41 -41
- package/lib/cast/bigint.js +2 -2
- package/lib/cast/boolean.js +3 -3
- package/lib/cast/double.js +2 -2
- package/lib/cast/int32.js +2 -2
- package/lib/cast/number.js +2 -2
- package/lib/cast/string.js +2 -2
- package/lib/cast.js +6 -6
- package/lib/collection.js +4 -4
- package/lib/connection.js +58 -58
- package/lib/cursor/aggregationCursor.js +6 -6
- package/lib/cursor/queryCursor.js +7 -7
- package/lib/document.js +176 -176
- package/lib/drivers/node-mongodb-native/collection.js +2 -2
- package/lib/drivers/node-mongodb-native/connection.js +8 -8
- package/lib/error/cast.js +2 -2
- package/lib/error/createCollectionsError.js +2 -2
- package/lib/error/divergentArray.js +1 -1
- package/lib/error/eachAsyncMultiError.js +1 -1
- package/lib/error/index.js +2 -2
- package/lib/error/invalidSchemaOption.js +1 -1
- package/lib/error/missingSchema.js +1 -1
- package/lib/error/objectParameter.js +3 -3
- package/lib/error/overwriteModel.js +1 -1
- package/lib/error/setOptionError.js +3 -3
- package/lib/error/strict.js +3 -3
- package/lib/error/strictPopulate.js +2 -2
- package/lib/error/syncIndexes.js +2 -2
- package/lib/error/validation.js +2 -2
- package/lib/error/validator.js +1 -1
- package/lib/error/version.js +2 -2
- package/lib/helpers/buildMiddlewareFilter.js +2 -2
- package/lib/helpers/clone.js +4 -4
- package/lib/helpers/createJSONSchemaTypeDefinition.js +4 -4
- package/lib/helpers/cursor/eachAsync.js +3 -3
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +3 -3
- package/lib/helpers/document/applyTimestamps.js +9 -9
- package/lib/helpers/document/applyVirtuals.js +6 -6
- package/lib/helpers/document/compile.js +10 -10
- package/lib/helpers/document/getDeepestSubdocumentForPath.js +2 -2
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
- package/lib/helpers/indexes/isIndexEqual.js +3 -3
- package/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
- package/lib/helpers/isMongooseObject.js +1 -1
- package/lib/helpers/isObject.js +2 -2
- package/lib/helpers/isSimpleValidator.js +2 -2
- package/lib/helpers/minimize.js +2 -2
- package/lib/helpers/model/applyHooks.js +1 -1
- package/lib/helpers/model/castBulkWrite.js +2 -2
- package/lib/helpers/pluralize.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +2 -2
- package/lib/helpers/populate/assignVals.js +6 -6
- package/lib/helpers/populate/createPopulateQueryFilter.js +2 -2
- package/lib/helpers/populate/getModelsMapForPopulate.js +12 -12
- package/lib/helpers/populate/getSchemaTypes.js +1 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/isPathExcluded.js +3 -3
- package/lib/helpers/projection/isSubpath.js +1 -1
- package/lib/helpers/query/castUpdate.js +14 -14
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +4 -4
- package/lib/helpers/query/handleImmutable.js +6 -6
- package/lib/helpers/schema/getIndexes.js +1 -1
- package/lib/helpers/schema/getSubdocumentStrictValue.js +1 -1
- package/lib/helpers/setDefaultsOnInsert.js +3 -3
- package/lib/helpers/update/modifiedPaths.js +2 -2
- package/lib/helpers/updateValidators.js +2 -2
- package/lib/model.js +263 -263
- package/lib/mongoose.js +54 -54
- package/lib/options/schemaArrayOptions.js +2 -2
- package/lib/options/schemaBufferOptions.js +1 -1
- package/lib/options/schemaNumberOptions.js +3 -3
- package/lib/options/schemaObjectIdOptions.js +2 -2
- package/lib/options/schemaStringOptions.js +6 -6
- package/lib/options/schemaTypeOptions.js +13 -13
- package/lib/options/virtualOptions.js +11 -11
- package/lib/query.js +222 -222
- package/lib/queryHelpers.js +4 -4
- package/lib/schema/array.js +18 -18
- package/lib/schema/bigint.js +13 -13
- package/lib/schema/boolean.js +13 -13
- package/lib/schema/buffer.js +14 -14
- package/lib/schema/date.js +16 -16
- package/lib/schema/decimal128.js +13 -13
- package/lib/schema/documentArray.js +15 -15
- package/lib/schema/documentArrayElement.js +5 -6
- package/lib/schema/double.js +12 -12
- package/lib/schema/int32.js +13 -13
- package/lib/schema/map.js +10 -10
- package/lib/schema/mixed.js +10 -10
- package/lib/schema/number.js +18 -18
- package/lib/schema/objectId.js +14 -14
- package/lib/schema/operators/text.js +3 -3
- package/lib/schema/string.js +17 -17
- package/lib/schema/subdocument.js +13 -13
- package/lib/schema/union.js +3 -3
- package/lib/schema/uuid.js +16 -16
- package/lib/schema.js +76 -76
- package/lib/schemaType.js +62 -62
- package/lib/stateMachine.js +5 -8
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +12 -12
- package/lib/types/arraySubdocument.js +8 -8
- package/lib/types/buffer.js +4 -4
- package/lib/types/documentArray/index.js +1 -1
- package/lib/types/documentArray/methods/index.js +5 -5
- package/lib/types/map.js +3 -3
- package/lib/types/subdocument.js +11 -11
- package/lib/utils.js +45 -45
- package/lib/virtualType.js +18 -18
- package/package.json +8 -5
- package/types/index.d.ts +16 -15
- package/types/inferschematype.d.ts +10 -0
- package/types/models.d.ts +8 -5
- package/types/schemaoptions.d.ts +1 -1
- package/types/virtuals.d.ts +10 -10
package/lib/document.js
CHANGED
|
@@ -77,11 +77,11 @@ const VERSION_ALL = VERSION_WHERE | VERSION_INC;
|
|
|
77
77
|
* The core Mongoose document constructor. You should not call this directly,
|
|
78
78
|
* the Mongoose [Model constructor](./api/model.html#Model) calls this for you.
|
|
79
79
|
*
|
|
80
|
-
* @param {
|
|
81
|
-
* @param {
|
|
82
|
-
* @param {
|
|
83
|
-
* @param {
|
|
84
|
-
* @param {
|
|
80
|
+
* @param {object} obj the values to set
|
|
81
|
+
* @param {object} [fields] optional object containing the fields which were selected in the query returning this document and any populated paths data
|
|
82
|
+
* @param {object} [options] various configuration options for the document
|
|
83
|
+
* @param {boolean} [options.defaults=true] if `false`, skip applying default values to this document.
|
|
84
|
+
* @param {boolean} [options.skipId=false] By default, Mongoose document if one is not provided and the document's schema does not override Mongoose's default `_id`. Set `skipId` to `true` to skip this generation step.
|
|
85
85
|
* @inherits NodeJS EventEmitter https://nodejs.org/api/events.html#class-eventemitter
|
|
86
86
|
* @event `init`: Emitted on a document after it has been retrieved from the db and fully hydrated by Mongoose.
|
|
87
87
|
* @event `save`: Emitted when the document is successfully saved
|
|
@@ -549,11 +549,11 @@ function $applyDefaultsToNested(val, path, doc) {
|
|
|
549
549
|
/**
|
|
550
550
|
* Builds the default doc structure
|
|
551
551
|
*
|
|
552
|
-
* @param {
|
|
553
|
-
* @param {
|
|
554
|
-
* @param {
|
|
555
|
-
* @param {
|
|
556
|
-
* @param {
|
|
552
|
+
* @param {object} obj
|
|
553
|
+
* @param {object} [fields]
|
|
554
|
+
* @param {boolean} [skipId]
|
|
555
|
+
* @param {boolean} [exclude]
|
|
556
|
+
* @param {object} [hasIncludedChildren]
|
|
557
557
|
* @api private
|
|
558
558
|
* @method $__buildDoc
|
|
559
559
|
* @memberOf Document
|
|
@@ -637,9 +637,9 @@ Document.prototype.toBSON = function() {
|
|
|
637
637
|
* This function triggers `init` [middleware](https://mongoosejs.com/docs/middleware.html).
|
|
638
638
|
* Note that `init` hooks are [synchronous](https://mongoosejs.com/docs/middleware.html#synchronous).
|
|
639
639
|
*
|
|
640
|
-
* @param {
|
|
641
|
-
* @param {
|
|
642
|
-
* @param {
|
|
640
|
+
* @param {object} doc raw document returned by mongo
|
|
641
|
+
* @param {object} [opts]
|
|
642
|
+
* @param {boolean} [opts.hydratedPopulatedDocs=false] If true, hydrate and mark as populated any paths that are populated in the raw document
|
|
643
643
|
* @param {Function} [fn]
|
|
644
644
|
* @api public
|
|
645
645
|
* @memberOf Document
|
|
@@ -679,7 +679,7 @@ Document.prototype.$init = function() {
|
|
|
679
679
|
* Internal "init" function
|
|
680
680
|
*
|
|
681
681
|
* @param {Document} doc
|
|
682
|
-
* @param {
|
|
682
|
+
* @param {object} [opts]
|
|
683
683
|
* @returns {Document} this
|
|
684
684
|
* @api private
|
|
685
685
|
*/
|
|
@@ -732,12 +732,12 @@ Document.prototype.$__init = function(doc, opts) {
|
|
|
732
732
|
/**
|
|
733
733
|
* Init helper.
|
|
734
734
|
*
|
|
735
|
-
* @param {
|
|
736
|
-
* @param {
|
|
737
|
-
* @param {
|
|
738
|
-
* @param {
|
|
739
|
-
* @param {
|
|
740
|
-
* @param {
|
|
735
|
+
* @param {object} self document instance
|
|
736
|
+
* @param {object} obj raw mongodb doc
|
|
737
|
+
* @param {object} doc object we are initializing
|
|
738
|
+
* @param {object} [opts] Optional Options
|
|
739
|
+
* @param {boolean} [opts.setters] Call `applySetters` instead of `cast`
|
|
740
|
+
* @param {string} [prefix] Prefix to add to each path
|
|
741
741
|
* @api private
|
|
742
742
|
*/
|
|
743
743
|
|
|
@@ -859,14 +859,14 @@ function init(self, obj, doc, opts, prefix) {
|
|
|
859
859
|
* - same as in [Model.updateOne](https://mongoosejs.com/docs/api/model.html#Model.updateOne)
|
|
860
860
|
*
|
|
861
861
|
* @see Model.updateOne https://mongoosejs.com/docs/api/model.html#Model.updateOne
|
|
862
|
-
* @param {
|
|
863
|
-
* @param {
|
|
864
|
-
* @param {
|
|
865
|
-
* @param {
|
|
866
|
-
* @param {
|
|
867
|
-
* @param {
|
|
868
|
-
* @param {
|
|
869
|
-
* @param {
|
|
862
|
+
* @param {object} update
|
|
863
|
+
* @param {object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
864
|
+
* @param {object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) and the [Mongoose lean tutorial](https://mongoosejs.com/docs/tutorials/lean.html).
|
|
865
|
+
* @param {boolean|'throw'} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
|
|
866
|
+
* @param {boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
|
|
867
|
+
* @param {boolean|object} [options.middleware=true] set to `false` to skip all user-defined middleware
|
|
868
|
+
* @param {boolean} [options.middleware.pre=true] set to `false` to skip only pre hooks
|
|
869
|
+
* @param {boolean} [options.middleware.post=true] set to `false` to skip only post hooks
|
|
870
870
|
* @return {Query}
|
|
871
871
|
* @api public
|
|
872
872
|
* @memberOf Document
|
|
@@ -911,8 +911,8 @@ Document.prototype.updateOne = function updateOne(update, options) {
|
|
|
911
911
|
* - same as in [Model.replaceOne](https://mongoosejs.com/docs/api/model.html#Model.replaceOne())
|
|
912
912
|
*
|
|
913
913
|
* @see Model.replaceOne https://mongoosejs.com/docs/api/model.html#Model.replaceOne()
|
|
914
|
-
* @param {
|
|
915
|
-
* @param {
|
|
914
|
+
* @param {object} doc
|
|
915
|
+
* @param {object} [options]
|
|
916
916
|
* @param {Function} [callback]
|
|
917
917
|
* @return {Query}
|
|
918
918
|
* @api public
|
|
@@ -993,7 +993,7 @@ Document.prototype.$session = function $session(session) {
|
|
|
993
993
|
* doc.$timestamps(false);
|
|
994
994
|
* await doc.save(); // Does **not** apply timestamps
|
|
995
995
|
*
|
|
996
|
-
* @param {
|
|
996
|
+
* @param {boolean} [value] overwrite the current session
|
|
997
997
|
* @return {Document|boolean|undefined} When used as a getter (no argument), a boolean will be returned indicating the timestamps option state or if unset "undefined" will be used, otherwise will return "this"
|
|
998
998
|
* @method $timestamps
|
|
999
999
|
* @api public
|
|
@@ -1026,7 +1026,7 @@ Document.prototype.$timestamps = function $timestamps(value) {
|
|
|
1026
1026
|
* for immutable properties. Behaves similarly to `set()`, except for it
|
|
1027
1027
|
* unsets all properties that aren't in `obj`.
|
|
1028
1028
|
*
|
|
1029
|
-
* @param {
|
|
1029
|
+
* @param {object} obj the object to overwrite this document with
|
|
1030
1030
|
* @method overwrite
|
|
1031
1031
|
* @memberOf Document
|
|
1032
1032
|
* @instance
|
|
@@ -1061,11 +1061,11 @@ Document.prototype.overwrite = function overwrite(obj) {
|
|
|
1061
1061
|
/**
|
|
1062
1062
|
* Alias for `set()`, used internally to avoid conflicts
|
|
1063
1063
|
*
|
|
1064
|
-
* @param {
|
|
1065
|
-
* @param {
|
|
1066
|
-
* @param {Schema|
|
|
1067
|
-
* @param {
|
|
1068
|
-
* @param {
|
|
1064
|
+
* @param {string|object} path path or object of key/vals to set
|
|
1065
|
+
* @param {any} val the value to set
|
|
1066
|
+
* @param {Schema|string|number|Buffer|any} [type] optionally specify a type for "on-the-fly" attributes
|
|
1067
|
+
* @param {object} [options] optionally specify options that modify the behavior of the set
|
|
1068
|
+
* @param {boolean} [options.merge=false] if true, setting a [nested path](https://mongoosejs.com/docs/subdocs.html#subdocuments-versus-nested-paths) will merge existing values rather than overwrite the whole object. So `doc.set('nested', { a: 1, b: 2 })` becomes `doc.set('nested.a', 1); doc.set('nested.b', 2);`
|
|
1069
1069
|
* @return {Document} this
|
|
1070
1070
|
* @method $set
|
|
1071
1071
|
* @memberOf Document
|
|
@@ -1629,10 +1629,10 @@ function _isManuallyPopulatedArray(val, ref) {
|
|
|
1629
1629
|
* // changing strict mode behavior
|
|
1630
1630
|
* doc.set(path, value, { strict: false });
|
|
1631
1631
|
*
|
|
1632
|
-
* @param {
|
|
1633
|
-
* @param {
|
|
1634
|
-
* @param {Schema|
|
|
1635
|
-
* @param {
|
|
1632
|
+
* @param {string|object} path path or object of key/vals to set
|
|
1633
|
+
* @param {any} val the value to set
|
|
1634
|
+
* @param {Schema|string|number|Buffer|any} [type] optionally specify a type for "on-the-fly" attributes
|
|
1635
|
+
* @param {object} [options] optionally specify options that modify the behavior of the set
|
|
1636
1636
|
* @return {Document} this
|
|
1637
1637
|
* @api public
|
|
1638
1638
|
* @method set
|
|
@@ -1646,14 +1646,14 @@ Document.prototype.set = Document.prototype.$set;
|
|
|
1646
1646
|
* Determine if we should mark this change as modified.
|
|
1647
1647
|
*
|
|
1648
1648
|
* @param {never} pathToMark UNUSED
|
|
1649
|
-
* @param {
|
|
1650
|
-
* @param {
|
|
1651
|
-
* @param {
|
|
1649
|
+
* @param {string|symbol} path
|
|
1650
|
+
* @param {object} options
|
|
1651
|
+
* @param {any} constructing
|
|
1652
1652
|
* @param {never} parts UNUSED
|
|
1653
1653
|
* @param {Schema} schema
|
|
1654
|
-
* @param {
|
|
1655
|
-
* @param {
|
|
1656
|
-
* @return {
|
|
1654
|
+
* @param {any} val
|
|
1655
|
+
* @param {any} priorVal
|
|
1656
|
+
* @return {boolean}
|
|
1657
1657
|
* @api private
|
|
1658
1658
|
* @method $__shouldModify
|
|
1659
1659
|
* @memberOf Document
|
|
@@ -1710,14 +1710,14 @@ Document.prototype.$__shouldModify = function(pathToMark, path, options, constru
|
|
|
1710
1710
|
/**
|
|
1711
1711
|
* Handles the actual setting of the value and marking the path modified if appropriate.
|
|
1712
1712
|
*
|
|
1713
|
-
* @param {
|
|
1714
|
-
* @param {
|
|
1715
|
-
* @param {
|
|
1716
|
-
* @param {
|
|
1713
|
+
* @param {string} pathToMark
|
|
1714
|
+
* @param {string|symbol} path
|
|
1715
|
+
* @param {object} options
|
|
1716
|
+
* @param {any} constructing
|
|
1717
1717
|
* @param {Array} parts
|
|
1718
1718
|
* @param {Schema} schema
|
|
1719
|
-
* @param {
|
|
1720
|
-
* @param {
|
|
1719
|
+
* @param {any} val
|
|
1720
|
+
* @param {any} priorVal
|
|
1721
1721
|
* @api private
|
|
1722
1722
|
* @method $__set
|
|
1723
1723
|
* @memberOf Document
|
|
@@ -1821,8 +1821,8 @@ Document.prototype.$__set = function(pathToMark, path, options, constructing, pa
|
|
|
1821
1821
|
/**
|
|
1822
1822
|
* Gets a raw value from a path (no getters)
|
|
1823
1823
|
*
|
|
1824
|
-
* @param {
|
|
1825
|
-
* @return {
|
|
1824
|
+
* @param {string} path
|
|
1825
|
+
* @return {any} Returns the value from the given `path`.
|
|
1826
1826
|
* @api private
|
|
1827
1827
|
*/
|
|
1828
1828
|
|
|
@@ -1854,8 +1854,8 @@ Document.prototype.$__getValue = function(path) {
|
|
|
1854
1854
|
* doc.counter += 2;
|
|
1855
1855
|
* await doc.save(); // Sends a `{ $set: { counter: 2 } }` to MongoDB
|
|
1856
1856
|
*
|
|
1857
|
-
* @param {
|
|
1858
|
-
* @param {
|
|
1857
|
+
* @param {string|Array} path path or paths to update
|
|
1858
|
+
* @param {number} val increment `path` by this value
|
|
1859
1859
|
* @return {Document} this
|
|
1860
1860
|
*/
|
|
1861
1861
|
|
|
@@ -1912,8 +1912,8 @@ Document.prototype.$inc = function $inc(path, val) {
|
|
|
1912
1912
|
/**
|
|
1913
1913
|
* Sets a raw value for a path (no casting, setters, transformations)
|
|
1914
1914
|
*
|
|
1915
|
-
* @param {
|
|
1916
|
-
* @param {
|
|
1915
|
+
* @param {string} path
|
|
1916
|
+
* @param {object} value
|
|
1917
1917
|
* @return {Document} this
|
|
1918
1918
|
* @api private
|
|
1919
1919
|
*/
|
|
@@ -1934,12 +1934,12 @@ Document.prototype.$__setValue = function(path, val) {
|
|
|
1934
1934
|
* // dynamic casting to a string
|
|
1935
1935
|
* doc.get('age', String) // "47"
|
|
1936
1936
|
*
|
|
1937
|
-
* @param {
|
|
1938
|
-
* @param {Schema|
|
|
1939
|
-
* @param {
|
|
1940
|
-
* @param {
|
|
1941
|
-
* @param {
|
|
1942
|
-
* @return {
|
|
1937
|
+
* @param {string} path
|
|
1938
|
+
* @param {Schema|string|number|Buffer|any} [type] optionally specify a type for on-the-fly attributes
|
|
1939
|
+
* @param {object} [options]
|
|
1940
|
+
* @param {boolean} [options.virtuals=false] Apply virtuals before getting this path
|
|
1941
|
+
* @param {boolean} [options.getters=true] If false, skip applying getters and just get the raw value
|
|
1942
|
+
* @return {any}
|
|
1943
1943
|
* @api public
|
|
1944
1944
|
*/
|
|
1945
1945
|
|
|
@@ -2031,7 +2031,7 @@ Document.prototype.$get = Document.prototype.get;
|
|
|
2031
2031
|
/**
|
|
2032
2032
|
* Returns the schematype for the given `path`.
|
|
2033
2033
|
*
|
|
2034
|
-
* @param {
|
|
2034
|
+
* @param {string} path
|
|
2035
2035
|
* @return {SchemaPath}
|
|
2036
2036
|
* @api private
|
|
2037
2037
|
* @method $__path
|
|
@@ -2060,7 +2060,7 @@ Document.prototype.$__path = function(path) {
|
|
|
2060
2060
|
* doc.markModified('mixed.type');
|
|
2061
2061
|
* doc.save() // changes to mixed.type are now persisted
|
|
2062
2062
|
*
|
|
2063
|
-
* @param {
|
|
2063
|
+
* @param {string} path the path to mark modified
|
|
2064
2064
|
* @param {Document} [scope] the scope to run validators with
|
|
2065
2065
|
* @api public
|
|
2066
2066
|
*/
|
|
@@ -2100,7 +2100,7 @@ Document.prototype.$__saveInitialState = function $__saveInitialState(path) {
|
|
|
2100
2100
|
* doc.unmarkModified('foo');
|
|
2101
2101
|
* doc.save(); // changes to foo will not be persisted
|
|
2102
2102
|
*
|
|
2103
|
-
* @param {
|
|
2103
|
+
* @param {string} path the path to unmark modified
|
|
2104
2104
|
* @api public
|
|
2105
2105
|
*/
|
|
2106
2106
|
|
|
@@ -2123,7 +2123,7 @@ Document.prototype.unmarkModified = function(path) {
|
|
|
2123
2123
|
* @memberOf Document
|
|
2124
2124
|
* @instance
|
|
2125
2125
|
* @method $ignore
|
|
2126
|
-
* @param {
|
|
2126
|
+
* @param {string} path the path to ignore
|
|
2127
2127
|
* @api public
|
|
2128
2128
|
*/
|
|
2129
2129
|
|
|
@@ -2150,7 +2150,7 @@ Document.prototype.$ignore = function(path) {
|
|
|
2150
2150
|
* doc.directModifiedPaths(); // ['nested.bar']
|
|
2151
2151
|
* doc.modifiedPaths(); // ['nested', 'nested.bar']
|
|
2152
2152
|
*
|
|
2153
|
-
* @return {
|
|
2153
|
+
* @return {string[]}
|
|
2154
2154
|
* @api public
|
|
2155
2155
|
*/
|
|
2156
2156
|
|
|
@@ -2175,12 +2175,12 @@ Document.prototype.directModifiedPaths = function() {
|
|
|
2175
2175
|
* doc.$isEmpty('nested'); // false
|
|
2176
2176
|
* doc.nested.$isEmpty(); // false
|
|
2177
2177
|
*
|
|
2178
|
-
* @param {
|
|
2178
|
+
* @param {string} [path]
|
|
2179
2179
|
* @memberOf Document
|
|
2180
2180
|
* @instance
|
|
2181
2181
|
* @api public
|
|
2182
2182
|
* @method $isEmpty
|
|
2183
|
-
* @return {
|
|
2183
|
+
* @return {boolean}
|
|
2184
2184
|
*/
|
|
2185
2185
|
|
|
2186
2186
|
Document.prototype.$isEmpty = function(path) {
|
|
@@ -2230,9 +2230,9 @@ function _isEmpty(v) {
|
|
|
2230
2230
|
/**
|
|
2231
2231
|
* Returns the list of paths that have been modified.
|
|
2232
2232
|
*
|
|
2233
|
-
* @param {
|
|
2234
|
-
* @param {
|
|
2235
|
-
* @return {
|
|
2233
|
+
* @param {object} [options]
|
|
2234
|
+
* @param {boolean} [options.includeChildren=false] if true, returns children of modified paths as well. For example, if false, the list of modified paths for `doc.colors = { primary: 'blue' };` will **not** contain `colors.primary`. If true, `modifiedPaths()` will return an array that contains `colors.primary`.
|
|
2235
|
+
* @return {string[]}
|
|
2236
2236
|
* @api public
|
|
2237
2237
|
*/
|
|
2238
2238
|
|
|
@@ -2311,10 +2311,10 @@ Document.prototype[documentModifiedPaths] = Document.prototype.modifiedPaths;
|
|
|
2311
2311
|
* doc.isModified('documents otherProp') // true
|
|
2312
2312
|
* doc.isDirectModified('documents') // false
|
|
2313
2313
|
*
|
|
2314
|
-
* @param {
|
|
2315
|
-
* @param {
|
|
2316
|
-
* @param {
|
|
2317
|
-
* @return {
|
|
2314
|
+
* @param {string} [path] optional
|
|
2315
|
+
* @param {object} [options]
|
|
2316
|
+
* @param {boolean} [options.ignoreAtomics=false] If true, doesn't return true if path is underneath an array that was modified with atomic operations like `push()`
|
|
2317
|
+
* @return {boolean}
|
|
2318
2318
|
* @api public
|
|
2319
2319
|
*/
|
|
2320
2320
|
|
|
@@ -2385,8 +2385,8 @@ Document.prototype[documentIsModified] = Document.prototype.isModified;
|
|
|
2385
2385
|
* @memberOf Document
|
|
2386
2386
|
* @instance
|
|
2387
2387
|
* @method $isDefault
|
|
2388
|
-
* @param {
|
|
2389
|
-
* @return {
|
|
2388
|
+
* @param {string} [path]
|
|
2389
|
+
* @return {boolean}
|
|
2390
2390
|
* @api public
|
|
2391
2391
|
*/
|
|
2392
2392
|
|
|
@@ -2421,8 +2421,8 @@ Document.prototype.$isDefault = function(path) {
|
|
|
2421
2421
|
* product.deleteOne(); // will execute a remove against the db
|
|
2422
2422
|
*
|
|
2423
2423
|
*
|
|
2424
|
-
* @param {
|
|
2425
|
-
* @return {
|
|
2424
|
+
* @param {boolean} [val] optional, overrides whether mongoose thinks the doc is deleted
|
|
2425
|
+
* @return {boolean|Document} whether mongoose thinks this doc is deleted.
|
|
2426
2426
|
* @method $isDeleted
|
|
2427
2427
|
* @memberOf Document
|
|
2428
2428
|
* @instance
|
|
@@ -2447,8 +2447,8 @@ Document.prototype.$isDeleted = function(val) {
|
|
|
2447
2447
|
* doc.isDirectModified('documents.0.title') // true
|
|
2448
2448
|
* doc.isDirectModified('documents') // false
|
|
2449
2449
|
*
|
|
2450
|
-
* @param {
|
|
2451
|
-
* @return {
|
|
2450
|
+
* @param {string|string[]} [path]
|
|
2451
|
+
* @return {boolean}
|
|
2452
2452
|
* @api public
|
|
2453
2453
|
*/
|
|
2454
2454
|
|
|
@@ -2486,8 +2486,8 @@ Document.prototype.isDirectModified = function(path) {
|
|
|
2486
2486
|
/**
|
|
2487
2487
|
* Checks if `path` is in the `init` state, that is, it was set by `Document#init()` and not modified since.
|
|
2488
2488
|
*
|
|
2489
|
-
* @param {
|
|
2490
|
-
* @return {
|
|
2489
|
+
* @param {string} [path]
|
|
2490
|
+
* @return {boolean}
|
|
2491
2491
|
* @api public
|
|
2492
2492
|
*/
|
|
2493
2493
|
|
|
@@ -2517,8 +2517,8 @@ Document.prototype.isInit = function(path) {
|
|
|
2517
2517
|
* doc.isSelected('name') // true
|
|
2518
2518
|
* doc.isSelected('age') // false
|
|
2519
2519
|
*
|
|
2520
|
-
* @param {
|
|
2521
|
-
* @return {
|
|
2520
|
+
* @param {string|string[]} path
|
|
2521
|
+
* @return {boolean}
|
|
2522
2522
|
* @api public
|
|
2523
2523
|
*/
|
|
2524
2524
|
|
|
@@ -2599,8 +2599,8 @@ Document.prototype.$__isSelected = Document.prototype.isSelected;
|
|
|
2599
2599
|
* doc.isDirectSelected('nested') // false
|
|
2600
2600
|
* })
|
|
2601
2601
|
*
|
|
2602
|
-
* @param {
|
|
2603
|
-
* @return {
|
|
2602
|
+
* @param {string} path
|
|
2603
|
+
* @return {boolean}
|
|
2604
2604
|
* @api public
|
|
2605
2605
|
*/
|
|
2606
2606
|
|
|
@@ -2661,13 +2661,13 @@ Document.prototype.isDirectSelected = function isDirectSelected(path) {
|
|
|
2661
2661
|
*
|
|
2662
2662
|
* await doc.validate({ validateModifiedOnly: false, pathsToSkip: ['name', 'email']});
|
|
2663
2663
|
*
|
|
2664
|
-
* @param {Array|
|
|
2665
|
-
* @param {
|
|
2666
|
-
* @param {
|
|
2664
|
+
* @param {Array|string} [pathsToValidate] list of paths to validate. If set, Mongoose will validate only the modified paths that are in the given list.
|
|
2665
|
+
* @param {object} [options] internal options
|
|
2666
|
+
* @param {boolean} [options.validateModifiedOnly=false] if `true` mongoose validates only modified paths.
|
|
2667
2667
|
* @param {Array|string} [options.pathsToSkip] list of paths to skip. If set, Mongoose will validate every modified path that is not in this list.
|
|
2668
|
-
* @param {
|
|
2669
|
-
* @param {
|
|
2670
|
-
* @param {
|
|
2668
|
+
* @param {boolean|object} [options.middleware=true] set to `false` to skip all user-defined middleware
|
|
2669
|
+
* @param {boolean} [options.middleware.pre=true] set to `false` to skip only pre hooks
|
|
2670
|
+
* @param {boolean} [options.middleware.post=true] set to `false` to skip only post hooks
|
|
2671
2671
|
* @return {Promise} Returns a Promise.
|
|
2672
2672
|
* @api public
|
|
2673
2673
|
*/
|
|
@@ -3254,12 +3254,12 @@ function _handlePathsToSkip(paths, pathsToSkip) {
|
|
|
3254
3254
|
* }
|
|
3255
3255
|
*
|
|
3256
3256
|
* @param {Array|string} [pathsToValidate] only validate the given paths
|
|
3257
|
-
* @param {
|
|
3258
|
-
* @param {
|
|
3257
|
+
* @param {object} [options] options for validation
|
|
3258
|
+
* @param {boolean} [options.validateModifiedOnly=false] If `true`, Mongoose will only validate modified paths, as opposed to modified paths and `required` paths.
|
|
3259
3259
|
* @param {Array|string} [options.pathsToSkip] list of paths to skip. If set, Mongoose will validate every modified path that is not in this list.
|
|
3260
|
-
* @param {
|
|
3261
|
-
* @param {
|
|
3262
|
-
* @param {
|
|
3260
|
+
* @param {boolean|object} [options.middleware=true] set to `false` to skip all user-defined middleware
|
|
3261
|
+
* @param {boolean} [options.middleware.pre=true] set to `false` to skip only pre hooks
|
|
3262
|
+
* @param {boolean} [options.middleware.post=true] set to `false` to skip only post hooks
|
|
3263
3263
|
* @return {ValidationError|undefined} ValidationError if there are errors during validation, or undefined if there is no error.
|
|
3264
3264
|
* @api public
|
|
3265
3265
|
*/
|
|
@@ -3407,10 +3407,10 @@ Document.prototype.validateSync = function(pathsToValidate, options) {
|
|
|
3407
3407
|
* value: 14 } } }
|
|
3408
3408
|
* })
|
|
3409
3409
|
*
|
|
3410
|
-
* @param {
|
|
3411
|
-
* @param {
|
|
3412
|
-
* @param {
|
|
3413
|
-
* @param {
|
|
3410
|
+
* @param {string} path the field to invalidate. For array elements, use the `array.i.field` syntax, where `i` is the 0-based index in the array.
|
|
3411
|
+
* @param {string|Error} err the error which states the reason `path` was invalid
|
|
3412
|
+
* @param {object|string|number|any} val optional invalid value
|
|
3413
|
+
* @param {string} [kind] optional `kind` property for the error
|
|
3414
3414
|
* @return {ValidationError} the current ValidationError, with all currently invalidated paths
|
|
3415
3415
|
* @api public
|
|
3416
3416
|
*/
|
|
@@ -3444,7 +3444,7 @@ Document.prototype.invalidate = function(path, err, val, kind) {
|
|
|
3444
3444
|
/**
|
|
3445
3445
|
* Marks a path as valid, removing existing validation errors.
|
|
3446
3446
|
*
|
|
3447
|
-
* @param {
|
|
3447
|
+
* @param {string} path the field to mark as valid
|
|
3448
3448
|
* @api public
|
|
3449
3449
|
* @memberOf Document
|
|
3450
3450
|
* @instance
|
|
@@ -3522,16 +3522,16 @@ function _checkImmutableSubpaths(subdoc, schematype, priorVal) {
|
|
|
3522
3522
|
* const newProduct = await product.save();
|
|
3523
3523
|
* newProduct === product; // true
|
|
3524
3524
|
*
|
|
3525
|
-
* @param {
|
|
3525
|
+
* @param {object} [options] options optional options
|
|
3526
3526
|
* @param {Session} [options.session=null] the [session](https://www.mongodb.com/docs/manual/reference/server-sessions/) associated with this save operation. If not specified, defaults to the [document's associated session](https://mongoosejs.com/docs/api/document.html#Document.prototype.$session()).
|
|
3527
|
-
* @param {
|
|
3528
|
-
* @param {
|
|
3529
|
-
* @param {
|
|
3530
|
-
* @param {
|
|
3531
|
-
* @param {
|
|
3532
|
-
* @param {
|
|
3533
|
-
* @param {
|
|
3534
|
-
* @param {
|
|
3527
|
+
* @param {object} [options.safe] (DEPRECATED) overrides [schema's safe option](https://mongoosejs.com/docs/guide.html#safe). Use the `w` option instead.
|
|
3528
|
+
* @param {boolean} [options.validateBeforeSave] set to false to save without validating.
|
|
3529
|
+
* @param {boolean} [options.validateModifiedOnly=false] If `true`, Mongoose will only validate modified paths, as opposed to modified paths and `required` paths.
|
|
3530
|
+
* @param {number|string} [options.w] set the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/#w-option). Overrides the [schema-level `writeConcern` option](https://mongoosejs.com/docs/guide.html#writeConcern)
|
|
3531
|
+
* @param {boolean} [options.j] set to true for MongoDB to wait until this `save()` has been [journaled before resolving the returned promise](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option). Overrides the [schema-level `writeConcern` option](https://mongoosejs.com/docs/guide.html#writeConcern)
|
|
3532
|
+
* @param {number} [options.wtimeout] sets a [timeout for the write concern](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout). Overrides the [schema-level `writeConcern` option](https://mongoosejs.com/docs/guide.html#writeConcern).
|
|
3533
|
+
* @param {boolean} [options.checkKeys=true] the MongoDB driver prevents you from saving keys that start with '$' or contain '.' by default. Set this option to `false` to skip that check. See [restrictions on field names](https://www.mongodb.com/docs/manual/reference/limits/#Restrictions-on-Field-Names)
|
|
3534
|
+
* @param {boolean} [options.timestamps=true] if `false` and [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this `save()`.
|
|
3535
3535
|
* @method save
|
|
3536
3536
|
* @memberOf Document
|
|
3537
3537
|
* @instance
|
|
@@ -3544,7 +3544,7 @@ function _checkImmutableSubpaths(subdoc, schematype, priorVal) {
|
|
|
3544
3544
|
/**
|
|
3545
3545
|
* Checks if a path is invalid
|
|
3546
3546
|
*
|
|
3547
|
-
* @param {
|
|
3547
|
+
* @param {string|string[]} [path] the field to check. If unset will always return "false"
|
|
3548
3548
|
* @method $isValid
|
|
3549
3549
|
* @memberOf Document
|
|
3550
3550
|
* @instance
|
|
@@ -3778,7 +3778,7 @@ Document.prototype.$__getArrayPathsToValidate = function() {
|
|
|
3778
3778
|
/**
|
|
3779
3779
|
* Get all subdocs (by bfs)
|
|
3780
3780
|
*
|
|
3781
|
-
* @param {
|
|
3781
|
+
* @param {object} [options] options. Currently for internal use.
|
|
3782
3782
|
* @return {Array}
|
|
3783
3783
|
* @api public
|
|
3784
3784
|
* @method $getAllSubdocs
|
|
@@ -3871,7 +3871,7 @@ Document.prototype.$__handleReject = function handleReject(err) {
|
|
|
3871
3871
|
/**
|
|
3872
3872
|
* Internal common logic for toObject() and toJSON()
|
|
3873
3873
|
*
|
|
3874
|
-
* @return {
|
|
3874
|
+
* @return {object}
|
|
3875
3875
|
* @api private
|
|
3876
3876
|
* @method $toObject
|
|
3877
3877
|
* @memberOf Document
|
|
@@ -4179,20 +4179,20 @@ Document.prototype.$__toObjectShallow = function $__toObjectShallow(schemaFields
|
|
|
4179
4179
|
*
|
|
4180
4180
|
* _During save, no custom options are applied to the document before being sent to the database._
|
|
4181
4181
|
*
|
|
4182
|
-
* @param {
|
|
4183
|
-
* @param {
|
|
4184
|
-
* @param {
|
|
4185
|
-
* @param {
|
|
4186
|
-
* @param {
|
|
4182
|
+
* @param {object} [options]
|
|
4183
|
+
* @param {boolean} [options.getters=false] if true, apply all getters, including virtuals
|
|
4184
|
+
* @param {boolean|object} [options.virtuals=false] if true, apply virtuals, including aliases. Use `{ getters: true, virtuals: false }` to just apply getters, not virtuals. An object of the form `{ pathsToSkip: ['someVirtual'] }` may also be used to omit specific virtuals.
|
|
4185
|
+
* @param {boolean} [options.aliases=true] if `options.virtuals = true`, you can set `options.aliases = false` to skip applying aliases. This option is a no-op if `options.virtuals = false`.
|
|
4186
|
+
* @param {boolean} [options.minimize=true] if true, omit any empty objects from the output
|
|
4187
4187
|
* @param {Function|null} [options.transform=null] if set, mongoose will call this function to allow you to transform the returned object
|
|
4188
|
-
* @param {
|
|
4189
|
-
* @param {
|
|
4190
|
-
* @param {
|
|
4191
|
-
* @param {
|
|
4192
|
-
* @param {
|
|
4193
|
-
* @param {
|
|
4194
|
-
* @param {
|
|
4195
|
-
* @return {
|
|
4188
|
+
* @param {boolean} [options.depopulate=false] if true, replace any conventionally populated paths with the original id in the output. Has no affect on virtual populated paths.
|
|
4189
|
+
* @param {boolean} [options.versionKey=true] if false, exclude the version key (`__v` by default) from the output
|
|
4190
|
+
* @param {boolean} [options.flattenMaps=false] if true, convert Maps to POJOs. Useful if you want to `JSON.stringify()` the result of `toObject()`.
|
|
4191
|
+
* @param {boolean} [options.flattenObjectIds=false] if true, convert any ObjectIds in the result to 24 character hex strings.
|
|
4192
|
+
* @param {boolean} [options.flattenUUIDs=false] if true, convert any UUIDs in the result to 36-character UUID strings in 8-4-4-4-12 format.
|
|
4193
|
+
* @param {boolean} [options.useProjection=false] - If true, omits fields that are excluded in this document's projection. Unless you specified a projection, this will omit any field that has `select: false` in the schema.
|
|
4194
|
+
* @param {boolean} [options.schemaFieldsOnly=false] - If true, the resulting object will only have fields that are defined in the document's schema. By default, `toObject()` returns all fields in the underlying document from MongoDB, including ones that are not listed in the schema.
|
|
4195
|
+
* @return {object} document as a plain old JavaScript object (POJO). This object may contain ObjectIds, Maps, Dates, mongodb.Binary, Buffers, and other non-POJO values.
|
|
4196
4196
|
* @see mongodb.Binary https://mongodb.github.io/node-mongodb-native/4.9/classes/Binary.html
|
|
4197
4197
|
* @api public
|
|
4198
4198
|
* @memberOf Document
|
|
@@ -4291,8 +4291,8 @@ function applyVirtuals(self, json, options, toObjectOptions) {
|
|
|
4291
4291
|
* Applies virtuals properties to `json`.
|
|
4292
4292
|
*
|
|
4293
4293
|
* @param {Document} self
|
|
4294
|
-
* @param {
|
|
4295
|
-
* @return {
|
|
4294
|
+
* @param {object} json
|
|
4295
|
+
* @return {object} `json`
|
|
4296
4296
|
* @api private
|
|
4297
4297
|
*/
|
|
4298
4298
|
|
|
@@ -4363,8 +4363,8 @@ function applyGetters(self, json) {
|
|
|
4363
4363
|
* Applies schema type transforms to `json`.
|
|
4364
4364
|
*
|
|
4365
4365
|
* @param {Document} self
|
|
4366
|
-
* @param {
|
|
4367
|
-
* @return {
|
|
4366
|
+
* @param {object} json
|
|
4367
|
+
* @return {object} `json`
|
|
4368
4368
|
* @api private
|
|
4369
4369
|
*/
|
|
4370
4370
|
|
|
@@ -4459,12 +4459,12 @@ function omitDeselectedFields(self, json) {
|
|
|
4459
4459
|
*
|
|
4460
4460
|
* See [schema options](https://mongoosejs.com/docs/guide.html#toJSON) for more information on setting `toJSON` option defaults.
|
|
4461
4461
|
*
|
|
4462
|
-
* @param {
|
|
4463
|
-
* @param {
|
|
4464
|
-
* @param {
|
|
4465
|
-
* @param {
|
|
4466
|
-
* @param {
|
|
4467
|
-
* @return {
|
|
4462
|
+
* @param {object} options
|
|
4463
|
+
* @param {boolean} [options.flattenMaps=true] if true, convert Maps to [POJOs](https://masteringjs.io/tutorials/fundamentals/pojo). Useful if you want to `JSON.stringify()` the result.
|
|
4464
|
+
* @param {boolean} [options.flattenObjectIds=false] if true, convert any ObjectIds in the result to 24 character hex strings.
|
|
4465
|
+
* @param {boolean} [options.flattenUUIDs=false] if true, convert any UUIDs in the result to 36-character UUID strings in 8-4-4-4-12 format.
|
|
4466
|
+
* @param {boolean} [options.schemaFieldsOnly=false] - If true, the resulting object will only have fields that are defined in the document's schema. By default, `toJSON()` returns all fields in the underlying document from MongoDB, including ones that are not listed in the schema.
|
|
4467
|
+
* @return {object}
|
|
4468
4468
|
* @see Document#toObject https://mongoosejs.com/docs/api/document.html#Document.prototype.toObject()
|
|
4469
4469
|
* @see JSON.stringify() in JavaScript https://thecodebarbarian.com/the-80-20-guide-to-json-stringify-in-javascript.html
|
|
4470
4470
|
* @api public
|
|
@@ -4534,7 +4534,7 @@ Document.prototype.$__setParent = function $__setParent(parent) {
|
|
|
4534
4534
|
/**
|
|
4535
4535
|
* Helper for console.log
|
|
4536
4536
|
*
|
|
4537
|
-
* @return {
|
|
4537
|
+
* @return {string}
|
|
4538
4538
|
* @api public
|
|
4539
4539
|
* @method inspect
|
|
4540
4540
|
* @memberOf Document
|
|
@@ -4568,7 +4568,7 @@ if (inspect.custom) {
|
|
|
4568
4568
|
/**
|
|
4569
4569
|
* Helper for console.log
|
|
4570
4570
|
*
|
|
4571
|
-
* @return {
|
|
4571
|
+
* @return {string}
|
|
4572
4572
|
* @api public
|
|
4573
4573
|
* @method toString
|
|
4574
4574
|
* @memberOf Document
|
|
@@ -4591,7 +4591,7 @@ Document.prototype.toString = function() {
|
|
|
4591
4591
|
* `deepEqual()`.
|
|
4592
4592
|
*
|
|
4593
4593
|
* @param {Document} [doc] a document to compare. If falsy, will always return "false".
|
|
4594
|
-
* @return {
|
|
4594
|
+
* @return {boolean}
|
|
4595
4595
|
* @api public
|
|
4596
4596
|
* @memberOf Document
|
|
4597
4597
|
* @instance
|
|
@@ -4636,21 +4636,21 @@ Document.prototype.equals = function(doc) {
|
|
|
4636
4636
|
* await doc.populate('fans', '-email');
|
|
4637
4637
|
* doc.fans[0].email // undefined because of 2nd param `select`
|
|
4638
4638
|
*
|
|
4639
|
-
* @param {
|
|
4640
|
-
* @param {
|
|
4639
|
+
* @param {string|object|Array} path either the path to populate or an object specifying all parameters, or either an array of those
|
|
4640
|
+
* @param {object|string} [select] Field selection for the population query
|
|
4641
4641
|
* @param {Model} [model] The model you wish to use for population. If not specified, populate will look up the model by the name in the Schema's `ref` field.
|
|
4642
|
-
* @param {
|
|
4643
|
-
* @param {
|
|
4644
|
-
* @param {
|
|
4642
|
+
* @param {object} [match] Conditions for the population query
|
|
4643
|
+
* @param {object} [options] Options for the population query (sort, etc)
|
|
4644
|
+
* @param {string} [options.path=null] The path to populate.
|
|
4645
4645
|
* @param {string|PopulateOptions} [options.populate=null] Recursively populate paths in the populated documents. See [deep populate docs](https://mongoosejs.com/docs/populate.html#deep-populate).
|
|
4646
4646
|
* @param {boolean} [options.retainNullValues=false] by default, Mongoose removes null and undefined values from populated arrays. Use this option to make `populate()` retain `null` and `undefined` array entries.
|
|
4647
4647
|
* @param {boolean} [options.getters=false] if true, Mongoose will call any getters defined on the `localField`. By default, Mongoose gets the raw value of `localField`. For example, you would need to set this option to `true` if you wanted to [add a `lowercase` getter to your `localField`](https://mongoosejs.com/docs/schematypes.html#schematype-options).
|
|
4648
4648
|
* @param {boolean} [options.clone=false] When you do `BlogPost.find().populate('author')`, blog posts with the same author will share 1 copy of an `author` doc. Enable this option to make Mongoose clone populated docs before assigning them.
|
|
4649
|
-
* @param {
|
|
4649
|
+
* @param {object|Function} [options.match=null] Add an additional filter to the populate query. Can be a filter object containing [MongoDB query syntax](https://www.mongodb.com/docs/manual/tutorial/query-documents/), or a function that returns a filter object.
|
|
4650
4650
|
* @param {Function} [options.transform=null] Function that Mongoose will call on every populated document that allows you to transform the populated document.
|
|
4651
|
-
* @param {
|
|
4652
|
-
* @param {
|
|
4653
|
-
* @param {
|
|
4651
|
+
* @param {object} [options.options=null] Additional options like `limit` and `lean`.
|
|
4652
|
+
* @param {boolean} [options.forceRepopulate=true] Set to `false` to prevent Mongoose from repopulating paths that are already populated
|
|
4653
|
+
* @param {boolean} [options.ordered=false] Set to `true` to execute any populate queries one at a time, as opposed to in parallel. We recommend setting this option to `true` if using transactions, especially if also populating multiple paths or paths with multiple models. MongoDB server does **not** support multiple operations in parallel on a single transaction.
|
|
4654
4654
|
* @param {Function} [callback] Callback
|
|
4655
4655
|
* @see population https://mongoosejs.com/docs/populate.html
|
|
4656
4656
|
* @see Query#select https://mongoosejs.com/docs/api/query.html#Query.prototype.select()
|
|
@@ -4748,10 +4748,10 @@ Document.prototype.$getPopulatedDocs = function $getPopulatedDocs() {
|
|
|
4748
4748
|
*
|
|
4749
4749
|
* If the path was not populated, returns `undefined`.
|
|
4750
4750
|
*
|
|
4751
|
-
* @param {
|
|
4752
|
-
* @param {
|
|
4753
|
-
* @param {
|
|
4754
|
-
* @return {Array|ObjectId|
|
|
4751
|
+
* @param {string} path
|
|
4752
|
+
* @param {any} [val]
|
|
4753
|
+
* @param {object} [options]
|
|
4754
|
+
* @return {Array|ObjectId|number|Buffer|string|undefined}
|
|
4755
4755
|
* @memberOf Document
|
|
4756
4756
|
* @instance
|
|
4757
4757
|
* @api public
|
|
@@ -4823,8 +4823,8 @@ Document.prototype.$populated = Document.prototype.populated;
|
|
|
4823
4823
|
* doc.$assertPopulated('likes', { likes });
|
|
4824
4824
|
*
|
|
4825
4825
|
*
|
|
4826
|
-
* @param {
|
|
4827
|
-
* @param {
|
|
4826
|
+
* @param {string|string[]} path path or array of paths to check. `$assertPopulated` throws if any of the given paths is not populated.
|
|
4827
|
+
* @param {object} [values] optional values to `$set()`. Convenient if you want to manually populate a path and assert that the path was populated in 1 call.
|
|
4828
4828
|
* @return {Document} this
|
|
4829
4829
|
* @memberOf Document
|
|
4830
4830
|
* @method $assertPopulated
|
|
@@ -4862,7 +4862,7 @@ Document.prototype.$assertPopulated = function $assertPopulated(path, values) {
|
|
|
4862
4862
|
*
|
|
4863
4863
|
* If the path was not provided, then all populated fields are returned to their unpopulated state.
|
|
4864
4864
|
*
|
|
4865
|
-
* @param {
|
|
4865
|
+
* @param {string|string[]} [path] Specific Path to depopulate. If unset, will depopulate all paths on the Document. Or multiple space-delimited paths.
|
|
4866
4866
|
* @return {Document} this
|
|
4867
4867
|
* @see Document.populate https://mongoosejs.com/docs/api/document.html#Document.prototype.populate()
|
|
4868
4868
|
* @api public
|
|
@@ -4950,8 +4950,8 @@ Document.prototype.depopulate = function(path) {
|
|
|
4950
4950
|
/**
|
|
4951
4951
|
* Returns the full path to this document.
|
|
4952
4952
|
*
|
|
4953
|
-
* @param {
|
|
4954
|
-
* @return {
|
|
4953
|
+
* @param {string} [path]
|
|
4954
|
+
* @return {string}
|
|
4955
4955
|
* @api private
|
|
4956
4956
|
* @method $__fullPath
|
|
4957
4957
|
* @memberOf Document
|
|
@@ -4997,7 +4997,7 @@ Document.prototype.$__fullPath = function(path) {
|
|
|
4997
4997
|
* change tracking state. Even if you `delete user.getChanges().$set`, Mongoose
|
|
4998
4998
|
* will still send a `$set` to the server.
|
|
4999
4999
|
*
|
|
5000
|
-
* @return {
|
|
5000
|
+
* @return {object}
|
|
5001
5001
|
* @api public
|
|
5002
5002
|
* @method getChanges
|
|
5003
5003
|
* @memberOf Document
|
|
@@ -5171,9 +5171,9 @@ Document.prototype.$__delta = function $__delta(pathsToSave, pathsToSaveSet) {
|
|
|
5171
5171
|
*
|
|
5172
5172
|
* @see https://github.com/Automattic/mongoose/issues/1334
|
|
5173
5173
|
* @param {Document} doc
|
|
5174
|
-
* @param {
|
|
5175
|
-
* @param {
|
|
5176
|
-
* @return {
|
|
5174
|
+
* @param {string} path
|
|
5175
|
+
* @param {any} array
|
|
5176
|
+
* @return {string|undefined}
|
|
5177
5177
|
* @api private
|
|
5178
5178
|
*/
|
|
5179
5179
|
|
|
@@ -5221,11 +5221,11 @@ function checkDivergentArray(doc, path, array) {
|
|
|
5221
5221
|
* well as track versioning for our where clause.
|
|
5222
5222
|
*
|
|
5223
5223
|
* @param {Document} self
|
|
5224
|
-
* @param {
|
|
5225
|
-
* @param {
|
|
5226
|
-
* @param {
|
|
5224
|
+
* @param {object} where Unused
|
|
5225
|
+
* @param {object} delta
|
|
5226
|
+
* @param {object} data
|
|
5227
5227
|
* @param {Mixed} val
|
|
5228
|
-
* @param {
|
|
5228
|
+
* @param {string} [op]
|
|
5229
5229
|
* @api private
|
|
5230
5230
|
*/
|
|
5231
5231
|
|
|
@@ -5293,9 +5293,9 @@ function operand(self, where, delta, data, val, op) {
|
|
|
5293
5293
|
* Compiles an update and where clause for a `val` with _atomics.
|
|
5294
5294
|
*
|
|
5295
5295
|
* @param {Document} self
|
|
5296
|
-
* @param {
|
|
5297
|
-
* @param {
|
|
5298
|
-
* @param {
|
|
5296
|
+
* @param {object} where
|
|
5297
|
+
* @param {object} delta
|
|
5298
|
+
* @param {object} data
|
|
5299
5299
|
* @param {Array} value
|
|
5300
5300
|
* @api private
|
|
5301
5301
|
*/
|
|
@@ -5374,8 +5374,8 @@ function handleAtomics(self, where, delta, data, value) {
|
|
|
5374
5374
|
* Determines whether versioning should be skipped for the given path
|
|
5375
5375
|
*
|
|
5376
5376
|
* @param {Document} self
|
|
5377
|
-
* @param {
|
|
5378
|
-
* @return {
|
|
5377
|
+
* @param {string} path
|
|
5378
|
+
* @return {boolean} true if versioning should be skipped for the given path
|
|
5379
5379
|
* @api private
|
|
5380
5380
|
*/
|
|
5381
5381
|
function shouldSkipVersioning(self, path) {
|