SchemaNumberOptions.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. * const schema = new Schema({
  45. * favoritePrime: {
  46. * type: Number,
  47. * enum: [3, 5, 7]
  48. * }
  49. * });
  50. * schema.path('favoritePrime').options.enum; // [3, 5, 7]
  51. *
  52. * @api public
  53. * @property enum
  54. * @memberOf SchemaNumberOptions
  55. * @type Array
  56. * @instance
  57. */
  58. Object.defineProperty(SchemaNumberOptions.prototype, 'enum', opts);
  59. /**
  60. * Sets default [populate options](/docs/populate.html#query-conditions).
  61. *
  62. * #### Example:
  63. * const schema = new Schema({
  64. * child: {
  65. * type: Number,
  66. * ref: 'Child',
  67. * populate: { select: 'name' }
  68. * }
  69. * });
  70. * const Parent = mongoose.model('Parent', schema);
  71. *
  72. * // Automatically adds `.select('name')`
  73. * Parent.findOne().populate('child');
  74. *
  75. * @api public
  76. * @property populate
  77. * @memberOf SchemaNumberOptions
  78. * @type Object
  79. * @instance
  80. */
  81. Object.defineProperty(SchemaNumberOptions.prototype, 'populate', opts);
  82. /*!
  83. * ignore
  84. */
  85. module.exports = SchemaNumberOptions;