@@ -79,6 +79,7 @@ let id = 0;
79
79
* - [pluginTags](/docs/guide.html#pluginTags): array of strings - defaults to `undefined`. If set and plugin called with `tags` option, will only apply that plugin to schemas with a matching tag.
80
80
*
81
81
* #### Options for Nested Schemas:
82
+ *
82
83
* - `excludeIndexes`: bool - defaults to `false`. If `true`, skip building indexes on this schema's paths.
83
84
*
84
85
* #### Note:
@@ -233,6 +234,7 @@ Object.defineProperty(Schema.prototype, 'childSchemas', {
233
234
* You do not need to interact with this property at all to use mongoose.
234
235
*
235
236
* #### Example:
237
+ *
236
238
* const schema = new Schema({});
237
239
* schema.virtual('answer').get(() => 42);
238
240
*
@@ -272,6 +274,7 @@ Schema.prototype.obj;
272
274
* in this schema, and the values are instances of the SchemaType class.
273
275
*
274
276
* #### Example:
277
+ *
275
278
* const schema = new Schema({ name: String }, { _id: false });
276
279
* schema.paths; // { name: SchemaString { ... } }
277
280
*
@@ -290,6 +293,7 @@ Schema.prototype.paths;
290
293
* Schema as a tree
291
294
*
292
295
* #### Example:
296
+ *
293
297
* {
294
298
* '_id' : ObjectId
295
299
* , 'nested' : {
@@ -395,8 +399,8 @@ Schema.prototype._clone = function _clone(Constructor) {
395
399
* newSchema.path('name'); // SchemaString { ... }
396
400
* newSchema.path('age'); // undefined
397
401
*
398
- * @param {Array } paths list of paths to pick
399
- * @param {Object } [options] options to pass to the schema constructor . Defaults to `this.options` if not set.
402
+ * @param {String[] } paths List of Paths to pick for the new Schema
403
+ * @param {Object } [options] Options to pass to the new Schema Constructor (same as `new Schema(.., Options)`) . Defaults to `this.options` if not set.
400
404
* @return {Schema }
401
405
* @api public
402
406
*/
@@ -426,8 +430,8 @@ Schema.prototype.pick = function(paths, options) {
426
430
/**
427
431
* Returns default options for this schema, merged with `options`.
428
432
*
429
- * @param {Object } options
430
- * @return {Object }
433
+ * @param {Object } [options] Options to overwrite the default options
434
+ * @return {Object } The merged options of `options` and the default options
431
435
* @api private
432
436
*/
433
437
@@ -755,6 +759,10 @@ Schema.prototype.clearIndexes = function clearIndexes() {
755
759
*
756
760
* const schema = new Schema(..);
757
761
* schema.methods.init = function () {} // potentially breaking
762
+ *
763
+ * @property reserved
764
+ * @memberOf Schema
765
+ * @static
758
766
*/
759
767
760
768
Schema . reserved = Object . create ( null ) ;
@@ -793,8 +801,8 @@ reserved.collection = 1;
793
801
* schema.path('name') // returns a SchemaType
794
802
* schema.path('name', Number) // changes the schemaType of `name` to Number
795
803
*
796
- * @param {String } path
797
- * @param {Object } constructor
804
+ * @param {String } path The name of the Path to get / set
805
+ * @param {Object } [obj] The Type to set the path to, if provided the path will be SET, otherwise the path will be GET
798
806
* @api public
799
807
*/
800
808
@@ -1059,6 +1067,7 @@ Object.defineProperty(Schema.prototype, 'base', {
1059
1067
*
1060
1068
* @param {String } path
1061
1069
* @param {Object } obj constructor
1070
+ * @param {Object } options
1062
1071
* @api private
1063
1072
*/
1064
1073
@@ -1316,6 +1325,7 @@ Schema.prototype.eachPath = function(fn) {
1316
1325
* Returns an Array of path strings that are required by this schema.
1317
1326
*
1318
1327
* #### Example:
1328
+ *
1319
1329
* const s = new Schema({
1320
1330
* name: { type: String, required: true },
1321
1331
* age: { type: String, required: true },
@@ -1324,7 +1334,7 @@ Schema.prototype.eachPath = function(fn) {
1324
1334
* s.requiredPaths(); // [ 'age', 'name' ]
1325
1335
*
1326
1336
* @api public
1327
- * @param {Boolean } invalidate refresh the cache
1337
+ * @param {Boolean } invalidate Refresh the cache
1328
1338
* @return {Array }
1329
1339
*/
1330
1340
@@ -1673,8 +1683,14 @@ Schema.prototype.post = function(name) {
1673
1683
* s.plugin(schema => console.log(schema.path('name').path));
1674
1684
* mongoose.model('Test', s); // Prints 'name'
1675
1685
*
1676
- * @param {Function } plugin callback
1677
- * @param {Object } [opts]
1686
+ * Or with Options:
1687
+ *
1688
+ * const s = new Schema({ name: String });
1689
+ * s.plugin((schema, opts) => console.log(opts.text, schema.path('name').path), { text: "Schema Path Name:" });
1690
+ * mongoose.model('Test', s); // Prints 'Schema Path Name: name'
1691
+ *
1692
+ * @param {Function } plugin The Plugin's callback
1693
+ * @param {Object } [opts] Options to pass to the plugin
1678
1694
* @see plugins
1679
1695
* @api public
1680
1696
*/
@@ -1722,13 +1738,14 @@ Schema.prototype.plugin = function(fn, opts) {
1722
1738
* });
1723
1739
*
1724
1740
* // later
1741
+ * const fizz = new Kitty;
1725
1742
* fizz.purr();
1726
1743
* fizz.scratch();
1727
1744
*
1728
1745
* NOTE: `Schema.method()` adds instance methods to the `Schema.methods` object. You can also add instance methods directly to the `Schema.methods` object as seen in the [guide](/docs/guide.html#methods)
1729
1746
*
1730
- * @param {String|Object } method name
1731
- * @param {Function } [fn]
1747
+ * @param {String|Object } name The Method Name for a single function, or a Object of "string-function" pairs.
1748
+ * @param {Function } [fn] The Function in a single-function definition.
1732
1749
* @api public
1733
1750
*/
1734
1751
@@ -1759,10 +1776,21 @@ Schema.prototype.method = function(name, fn, options) {
1759
1776
* const Drink = mongoose.model('Drink', schema);
1760
1777
* await Drink.findByName('LaCroix');
1761
1778
*
1779
+ * If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as methods.
1780
+ *
1781
+ * schema.static({
1782
+ * findByName: function () {..}
1783
+ * , findByCost: function () {..}
1784
+ * });
1785
+ *
1786
+ * const Drink = mongoose.model('Drink', schema);
1787
+ * await Drink.findByName('LaCroix');
1788
+ * await Drink.findByCost(3);
1789
+ *
1762
1790
* If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as statics.
1763
1791
*
1764
- * @param {String|Object } name
1765
- * @param {Function } [fn]
1792
+ * @param {String|Object } name The Method Name for a single function, or a Object of "string-function" pairs.
1793
+ * @param {Function } [fn] The Function in a single-function definition.
1766
1794
* @api public
1767
1795
* @see Statics /docs/guide.html#statics
1768
1796
*/
@@ -1785,7 +1813,7 @@ Schema.prototype.static = function(name, fn) {
1785
1813
*
1786
1814
* schema.index({ first: 1, last: -1 })
1787
1815
*
1788
- * @param {Object } fields
1816
+ * @param {Object } fields The Fields to index, with the order, available values: `1 | -1 | '2d' | '2dsphere' | 'geoHaystack' | 'hashed' | 'text'`
1789
1817
* @param {Object } [options] Options to pass to [MongoDB driver's `createIndex()` function](https://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#createIndex)
1790
1818
* @param {String | number } [options.expires=null] Mongoose-specific syntactic sugar, uses [ms](https://www.npmjs.com/package/ms) to convert `expires` option into seconds for the `expireAfterSeconds` in the above link.
1791
1819
* @api public
@@ -1812,8 +1840,8 @@ Schema.prototype.index = function(fields, options) {
1812
1840
* schema.set('strict', false); // Sets 'strict' to false
1813
1841
* schema.set('strict'); // 'false'
1814
1842
*
1815
- * @param {String } key option name
1816
- * @param {Object } [value] if not passed, the current option value is returned
1843
+ * @param {String } key The name of the option to set the value to
1844
+ * @param {Object } [value] The value to set the option to, if not passed, the option will be reset to default
1817
1845
* @see Schema ./
1818
1846
* @api public
1819
1847
*/
@@ -1861,7 +1889,7 @@ Schema.prototype.set = function(key, value, _tags) {
1861
1889
* schema.set('strict', false);
1862
1890
* schema.get('strict'); // false
1863
1891
*
1864
- * @param {String } key option name
1892
+ * @param {String } key The name of the Option to get the current value for
1865
1893
* @api public
1866
1894
* @return {Any } the option's value
1867
1895
*/
@@ -1926,7 +1954,7 @@ Schema.prototype.indexes = function() {
1926
1954
/**
1927
1955
* Creates a virtual type with the given name.
1928
1956
*
1929
- * @param {String } name
1957
+ * @param {String } name The name of the Virtual
1930
1958
* @param {Object } [options]
1931
1959
* @param {String|Model } [options.ref] model name or model instance. Marks this as a [populate virtual](/docs/populate.html#populate-virtuals).
1932
1960
* @param {String|Function } [options.localField] Required for populate virtuals. See [populate virtual docs](/docs/populate.html#populate-virtuals) for more information.
@@ -2044,8 +2072,8 @@ Schema.prototype.virtual = function(name, options) {
2044
2072
/**
2045
2073
* Returns the virtual type with the given `name`.
2046
2074
*
2047
- * @param {String } name
2048
- * @return {VirtualType }
2075
+ * @param {String } name The name of the Virtual to get
2076
+ * @return {VirtualType|null }
2049
2077
*/
2050
2078
2051
2079
Schema . prototype . virtualpath = function ( name ) {
@@ -2062,7 +2090,13 @@ Schema.prototype.virtualpath = function(name) {
2062
2090
* schema.path('name'); // Undefined
2063
2091
* schema.path('age'); // SchemaNumber { ... }
2064
2092
*
2065
- * @param {String|Array } path
2093
+ * Or as a Array:
2094
+ *
2095
+ * schema.remove(['name', 'age']);
2096
+ * schema.path('name'); // Undefined
2097
+ * schema.path('age'); // Undefined
2098
+ *
2099
+ * @param {String|Array } path The Path(s) to remove
2066
2100
* @return {Schema } the Schema instance
2067
2101
* @api public
2068
2102
*/
@@ -2150,7 +2184,7 @@ function _deletePath(schema, name) {
2150
2184
* userSchema.loadClass(UserClass);
2151
2185
* ```
2152
2186
*
2153
- * @param {Function } model
2187
+ * @param {Function } model The Class to load
2154
2188
* @param {Boolean } [virtualsOnly] if truthy, only pulls virtuals from the class, not methods or statics
2155
2189
*/
2156
2190
Schema . prototype . loadClass = function ( model , virtualsOnly ) {
0 commit comments