schemaObjectIdOptions.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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](https://mongoosejs.com/docs/populate.html#query-conditions).
  29. *
  30. * #### Example:
  31. *
  32. * const schema = new Schema({
  33. * child: {
  34. * type: 'ObjectId',
  35. * ref: 'Child',
  36. * populate: { select: 'name' }
  37. * }
  38. * });
  39. * const Parent = mongoose.model('Parent', schema);
  40. *
  41. * // Automatically adds `.select('name')`
  42. * Parent.findOne().populate('child');
  43. *
  44. * @api public
  45. * @property populate
  46. * @memberOf SchemaObjectIdOptions
  47. * @type {Object}
  48. * @instance
  49. */
  50. Object.defineProperty(SchemaObjectIdOptions.prototype, 'populate', opts);
  51. /*!
  52. * ignore
  53. */
  54. module.exports = SchemaObjectIdOptions;