Skip to content

Commit

Permalink
fix(document): avoid using childSchemas.path for compatibility with p…
Browse files Browse the repository at this point in the history
…re-Mongoose-8.8 schemas

Fix #15071
  • Loading branch information
vkarpov15 committed Dec 26, 2024
1 parent 4081e5c commit 7bb0d10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -3703,8 +3703,10 @@ Document.prototype.$getAllSubdocs = function(options) {
const subDocs = [];
function getSubdocs(doc) {
const newSubdocs = [];
for (const { path } of doc.$__schema.childSchemas) {
const val = doc.$__getValue(path);

for (const { model } of doc.$__schema.childSchemas) {
// Avoid using `childSchemas.path` to avoid compatibility versions with pre-8.8 versions of Mongoose
const val = doc.$__getValue(model.path);
if (val == null) {
continue;
}
Expand All @@ -3726,6 +3728,7 @@ Document.prototype.$getAllSubdocs = function(options) {
}
}
}

for (const subdoc of newSubdocs) {
getSubdocs(subdoc);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ exports.getValue = function(path, obj, map) {
const mapGetterOptions = Object.freeze({ getters: false });

function getValueLookup(obj, part) {
if (part === '$*' && obj instanceof Map) {
return obj;
}
let _from = obj?._doc || obj;
if (_from != null && _from.isMongooseArrayProxy) {
_from = _from.__array;
Expand Down

0 comments on commit 7bb0d10

Please sign in to comment.