UNPKG

412 BJavaScriptView Raw
1'use strict';
2
3const addAutoId = require('./addAutoId');
4
5module.exports = function handleIdOption(schema, options) {
6 if (options == null || options._id == null) {
7 return schema;
8 }
9
10 schema = schema.clone();
11 if (!options._id) {
12 schema.remove('_id');
13 schema.options._id = false;
14 } else if (!schema.paths['_id']) {
15 addAutoId(schema);
16 schema.options._id = true;
17 }
18
19 return schema;
20};
\No newline at end of file