schemaNumberOptions.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. 'use strict';
  2. const SchemaTypeOptions = require('./schemaTypeOptions');
  3. /**
  4. * The options defined on a Number schematype.
  5. *
  6. * #### Example:
  7. *
  8. * const schema = new Schema({ count: Number });
  9. * schema.path('count').options; // SchemaNumberOptions instance
  10. *
  11. * @api public
  12. * @inherits SchemaTypeOptions
  13. * @constructor SchemaNumberOptions
  14. */
  15. class SchemaNumberOptions extends SchemaTypeOptions {}
  16. const opts = require('./propertyOptions');
  17. /**
  18. * If set, Mongoose adds a validator that checks that this path is at least the
  19. * given `min`.
  20. *
  21. * @api public
  22. * @property min
  23. * @memberOf SchemaNumberOptions
  24. * @type {Number}
  25. * @instance
  26. */
  27. Object.defineProperty(SchemaNumberOptions.prototype, 'min', opts);
  28. /**
  29. * If set, Mongoose adds a validator that checks that this path is less than the
  30. * given `max`.
  31. *
  32. * @api public
  33. * @property max
  34. * @memberOf SchemaNumberOptions
  35. * @type {Number}
  36. * @instance
  37. */
  38. Object.defineProperty(SchemaNumberOptions.prototype, 'max', opts);
  39. /**
  40. * If set, Mongoose adds a validator that checks that this path is strictly
  41. * equal to one of the given values.
  42. *
  43. * #### Example:
  44. *
  45. * const schema = new Schema({
  46. * favoritePrime: {
  47. * type: Number,
  48. * enum: [3, 5, 7]
  49. * }
  50. * });
  51. * schema.path('favoritePrime').options.enum; // [3, 5, 7]
  52. *
  53. * @api public
  54. * @property enum
  55. * @memberOf SchemaNumberOptions
  56. * @type {Array}
  57. * @instance
  58. */
  59. Object.defineProperty(SchemaNumberOptions.prototype, 'enum', opts);
  60. /**
  61. * Sets default [populate options](https://mongoosejs.com/docs/populate.html#query-conditions).
  62. *
  63. * #### Example:
  64. *
  65. * const schema = new Schema({
  66. * child: {
  67. * type: Number,
  68. * ref: 'Child',
  69. * populate: { select: 'name' }
  70. * }
  71. * });
  72. * const Parent = mongoose.model('Parent', schema);
  73. *
  74. * // Automatically adds `.select('name')`
  75. * Parent.findOne().populate('child');
  76. *
  77. * @api public
  78. * @property populate
  79. * @memberOf SchemaNumberOptions
  80. * @type {Object}
  81. * @instance
  82. */
  83. Object.defineProperty(SchemaNumberOptions.prototype, 'populate', opts);
  84. /*!
  85. * ignore
  86. */
  87. module.exports = SchemaNumberOptions;