Skip to content

Commit

Permalink
fix(update): quick improvement for #7909
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jun 22, 2019
1 parent 0314b02 commit 4c4973a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/helpers/setDefaultsOnInsert.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ module.exports = function(filter, schema, castedDoc, options) {

schema.eachPath(function(path, schemaType) {
// Skip single nested paths if underneath a map
if (schemaType.$isSingleNested && !schemaType.path.endsWith('.$*')) {
const isUnderneathMap = schemaType.path.endsWith('.$*') ||
schemaType.path.indexOf('.$*.') !== -1;
if (schemaType.$isSingleNested && !isUnderneathMap) {
// Only handle nested schemas 1-level deep to avoid infinite
// recursion re: https://github.com/mongodb-js/mongoose-autopopulate/issues/11
schemaType.schema.eachPath(function(_path, _schemaType) {
Expand Down
2 changes: 1 addition & 1 deletion test/model.findOneAndUpdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ describe('model: findOneAndUpdate:', function() {
});

it('skips setting defaults within maps (gh-7909)', function() {
const socialMediaHandleSchema = Schema({ links: [String] });
const socialMediaHandleSchema = Schema({ links: [String] });
const profileSchema = Schema({
username: String,
socialMediaHandles: {
Expand Down

0 comments on commit 4c4973a

Please sign in to comment.