Refactoring day1
This commit is contained in:
17
node_modules/mongoose/lib/helpers/setDefaultsOnInsert.js
generated
vendored
17
node_modules/mongoose/lib/helpers/setDefaultsOnInsert.js
generated
vendored
@@ -14,17 +14,6 @@ const get = require('./get');
|
||||
*/
|
||||
|
||||
module.exports = function(filter, schema, castedDoc, options) {
|
||||
options = options || {};
|
||||
|
||||
const shouldSetDefaultsOnInsert =
|
||||
options.setDefaultsOnInsert != null ?
|
||||
options.setDefaultsOnInsert :
|
||||
schema.base.options.setDefaultsOnInsert;
|
||||
|
||||
if (!options.upsert || !shouldSetDefaultsOnInsert) {
|
||||
return castedDoc;
|
||||
}
|
||||
|
||||
const keys = Object.keys(castedDoc || {});
|
||||
const updatedKeys = {};
|
||||
const updatedValues = {};
|
||||
@@ -33,6 +22,12 @@ module.exports = function(filter, schema, castedDoc, options) {
|
||||
|
||||
let hasDollarUpdate = false;
|
||||
|
||||
options = options || {};
|
||||
|
||||
if (!options.upsert || !options.setDefaultsOnInsert) {
|
||||
return castedDoc;
|
||||
}
|
||||
|
||||
for (let i = 0; i < numKeys; ++i) {
|
||||
if (keys[i].startsWith('$')) {
|
||||
modifiedPaths(castedDoc[keys[i]], '', modified);
|
||||
|
||||
Reference in New Issue
Block a user