diff --git a/lib/document.js b/lib/document.js index 577c1540a68..d61789fe69a 100644 --- a/lib/document.js +++ b/lib/document.js @@ -1413,9 +1413,13 @@ function _getPathsToValidate(doc) { len = subdocs.length; for (i = 0; i < len; ++i) { subdoc = subdocs[i]; - if (subdoc.$isSingleNested && - doc.isModified(subdoc.$basePath) && + if (doc.isModified(subdoc.$basePath) && !doc.isDirectModified(subdoc.$basePath)) { + // Remove child paths for now, because we'll be validating the whole + // subdoc + paths = paths.filter(function(p) { + return p != null && p.indexOf(subdoc.$basePath + '.') !== 0; + }); paths.push(subdoc.$basePath); } } @@ -1499,8 +1503,8 @@ Document.prototype.$__validate = function(callback) { }); } - var validating = {}, - total = 0; + var validated = {}; + var total = 0; var complete = function() { var error = _complete(); @@ -1513,11 +1517,11 @@ Document.prototype.$__validate = function(callback) { }; var validatePath = function(path) { - if (validating[path]) { + if (path == null || validated[path]) { return; } - validating[path] = true; + validated[path] = true; total++; process.nextTick(function() { diff --git a/lib/schema/documentarray.js b/lib/schema/documentarray.js index 97ee114262c..9f4c469e066 100644 --- a/lib/schema/documentarray.js +++ b/lib/schema/documentarray.js @@ -27,6 +27,7 @@ var utils = require('../utils'); function DocumentArray(key, schema, options) { var EmbeddedDocument = _createConstructor(schema, options); + EmbeddedDocument.prototype.$basePath = key; ArrayType.call(this, key, EmbeddedDocument, options);