function getSubdocs(doc) {
    const newSubdocs = [];

    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;
      }
      if (val.$__) {
        newSubdocs.push(val);
      }
      if (Array.isArray(val)) {
        for (const el of val) {
          if (el != null && el.$__) {
            newSubdocs.push(el);
          }
        }
      }
      if (val instanceof Map) {
        for (const el of val.values()) {
          if (el != null && el.$__) {
            newSubdocs.push(el);
          }
        }
      }
    }

    for (const subdoc of newSubdocs) {
      getSubdocs(subdoc);
    }
    subDocs.push(...newSubdocs);
  }
Get all subdocs (by bfs)

@param {Object} [options] options. Currently for internal use.
@return {Array}
@api public
@method $getAllSubdocs
@memberOf Document
@instance