handleIdOption.js 413 B

1234567891011121314151617181920
  1. 'use strict';
  2. const addAutoId = require('./addAutoId');
  3. module.exports = function handleIdOption(schema, options) {
  4. if (options == null || options._id == null) {
  5. return schema;
  6. }
  7. schema = schema.clone();
  8. if (!options._id) {
  9. schema.remove('_id');
  10. schema.options._id = false;
  11. } else if (!schema.paths['_id']) {
  12. addAutoId(schema);
  13. schema.options._id = true;
  14. }
  15. return schema;
  16. };