Skip to content

Commit 0bf4563

Browse files
authored
Merge pull request Automattic#15131 from Automattic/vkarpov15/Automatticgh-15071-2
fix(document): avoid using childSchemas.path for compatibility with pre-Mongoose-8.8 schemas
2 parents ddd95b8 + 7bb0d10 commit 0bf4563

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/document.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,8 +3703,10 @@ Document.prototype.$getAllSubdocs = function(options) {
37033703
const subDocs = [];
37043704
function getSubdocs(doc) {
37053705
const newSubdocs = [];
3706-
for (const { path } of doc.$__schema.childSchemas) {
3707-
const val = doc.$__getValue(path);
3706+
3707+
for (const { model } of doc.$__schema.childSchemas) {
3708+
// Avoid using `childSchemas.path` to avoid compatibility versions with pre-8.8 versions of Mongoose
3709+
const val = doc.$__getValue(model.path);
37083710
if (val == null) {
37093711
continue;
37103712
}
@@ -3726,6 +3728,7 @@ Document.prototype.$getAllSubdocs = function(options) {
37263728
}
37273729
}
37283730
}
3731+
37293732
for (const subdoc of newSubdocs) {
37303733
getSubdocs(subdoc);
37313734
}

lib/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,9 @@ exports.getValue = function(path, obj, map) {
631631
const mapGetterOptions = Object.freeze({ getters: false });
632632

633633
function getValueLookup(obj, part) {
634+
if (part === '$*' && obj instanceof Map) {
635+
return obj;
636+
}
634637
let _from = obj?._doc || obj;
635638
if (_from != null && _from.isMongooseArrayProxy) {
636639
_from = _from.__array;

0 commit comments

Comments
 (0)