SchemaObjectIdOptions.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. const SchemaTypeOptions = require('./SchemaTypeOptions');
  3. /**
  4. * The options defined on an ObjectId schematype.
  5. *
  6. * #### Example:
  7. *
  8. * const schema = new Schema({ testId: mongoose.ObjectId });
  9. * schema.path('testId').options; // SchemaObjectIdOptions instance
  10. *
  11. * @api public
  12. * @inherits SchemaTypeOptions
  13. * @constructor SchemaObjectIdOptions
  14. */
  15. class SchemaObjectIdOptions extends SchemaTypeOptions {}
  16. const opts = require('./propertyOptions');
  17. /**
  18. * If truthy, uses Mongoose's default built-in ObjectId path.
  19. *
  20. * @api public
  21. * @property auto
  22. * @memberOf SchemaObjectIdOptions
  23. * @type Boolean
  24. * @instance
  25. */
  26. Object.defineProperty(SchemaObjectIdOptions.prototype, 'auto', opts);
  27. /**
  28. * Sets default [populate options](/docs/populate.html#query-conditions).
  29. *
  30. * #### Example:
  31. * const schema = new Schema({
  32. * child: {
  33. * type: 'ObjectId',
  34. * ref: 'Child',
  35. * populate: { select: 'name' }
  36. * }
  37. * });
  38. * const Parent = mongoose.model('Parent', schema);
  39. *
  40. * // Automatically adds `.select('name')`
  41. * Parent.findOne().populate('child');
  42. *
  43. * @api public
  44. * @property populate
  45. * @memberOf SchemaObjectIdOptions
  46. * @type Object
  47. * @instance
  48. */
  49. Object.defineProperty(SchemaObjectIdOptions.prototype, 'populate', opts);
  50. /*!
  51. * ignore
  52. */
  53. module.exports = SchemaObjectIdOptions;