Automattic / mongoose

MongoDB object modeling designed to work in an asynchronous environment.
https://mongoosejs.com
MIT License
26.96k stars 3.84k forks source link

"RangeError: Maximum call stack size exceeded" after upgrading from mongoose 6.4.5 to 6.5.1 #12220

Closed thetif closed 2 years ago

thetif commented 2 years ago

Prerequisites

Mongoose version

6.5.1

Node.js version

16.16.0

MongoDB version

5.0.9

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.5

Issue

I am trying to upgrade our mongoose to the newest version, but I am having trouble with adding things to mongo now. I was seeing an error MongooseError: Conflicting dotted paths when setting document path, key: "mmis.50", value: true" but now I'm consistently getting an RangeError: Maximum call stack size exceeded. I have tried adding minimize: false to all of my subdocuments but it doesn't seem to be helping. Here is my schema, could you please help me figure out where my issue is?

const mongoose = require('mongoose');

const quarterlyFFP = new mongoose.Schema(
  {
    combined: {
      type: Number,
      default: 0
    },
    contractors: {
      type: Number,
      default: 0
    },
    inHouse: {
      type: Number,
      default: 0
    }
  },
  {
    _id: false,
    minimize: false
  }
);

const federalCitation = new mongoose.Schema(
  {
    title: String,
    checked: {
      type: Boolean,
      default: null
    },
    explanation: String
  },
  {
    _id: false,
    minimize: false
  }
);

const incentivePayment = new mongoose.Schema(
  {
    1: {
      type: Number,
      default: 0
    },
    2: {
      type: Number,
      default: 0
    },
    3: {
      type: Number,
      default: 0
    },
    4: {
      type: Number,
      default: 0
    }
  },
  {
    _id: false,
    minimize: false
  }
);

const actualExpenditures = new mongoose.Schema(
  {
    federalActual: {
      type: Number,
      default: 0
    },
    totalApproved: {
      type: Number,
      default: 0
    }
  },
  {
    _id: false,
    minimize: false
  }
);

const apdSchema = new mongoose.Schema(
  {
    createdAt: {
      type: Date,
      default: Date.now,
      required: true
    },
    updatedAt: {
      type: Date,
      default: Date.now,
      required: true
    },
    status: {
      type: String,
      enum: ['draft', 'archived', 'submitted', 'approved'],
      required: true
    },
    stateId: {
      type: String,
      required: true
    },
    name: String,
    years: [
      {
        _id: false,
        type: String,
        validate: {
          validator: v => {
            const re = /^[0-9]{4}$/;
            return v == null || re.test(v);
          },
          message: 'Provided year is invalid.'
        }
      }
    ],
    apdOverview: {
      programOverview: String,
      narrativeHIT: String,
      narrativeHIE: String,
      narrativeMMIS: String
    },
    keyStatePersonnel: {
      medicaidDirector: {
        name: String,
        email: String,
        phone: String
      },
      medicaidOffice: {
        address1: String,
        address2: String,
        city: String,
        state: String,
        zip: String
      },
      keyPersonnel: [
        {
          _id: false,
          name: String,
          position: String,
          email: String,
          isPrimary: Boolean,
          fte: {
            type: Map,
            of: {
              type: Number,
              default: 0
            }
          },
          hasCosts: Boolean,
          costs: {
            type: Map,
            of: {
              type: Number,
              default: 0
            }
          }
        }
      ]
    },
    previousActivities: {
      previousActivitySummary: String,
      actualExpenditures: {
        type: Map,
        of: new mongoose.Schema(
          {
            hithie: actualExpenditures,
            mmis: {
              50: actualExpenditures,
              75: actualExpenditures,
              90: actualExpenditures
            }
          },
          {
            _id: false,
            minimize: false
          }
        )
      }
    },
    activities: [
      {
        _id: false,
        alternatives: String,
        contractorResources: [
          {
            _id: false,
            description: String,
            end: Date,
            hourly: {
              type: Map,
              of: new mongoose.Schema(
                {
                  hours: {
                    type: Number,
                    default: 0
                  },
                  rate: {
                    type: Number,
                    default: 0
                  }
                },
                {
                  _id: false,
                  minimize: false
                }
              )
            },
            useHourly: Boolean,
            name: String,
            start: Date,
            totalCost: {
              type: Number
            },
            years: {
              type: Map,
              of: Number
            }
          }
        ],
        costAllocation: {
          type: Map,
          of: new mongoose.Schema(
            {
              ffp: {
                federal: {
                  type: Number,
                  default: 0
                },
                state: {
                  type: Number,
                  default: 0
                }
              },
              other: {
                type: Number,
                default: 0
              }
            },
            {
              _id: false,
              minimize: false
            }
          )
        },
        costAllocationNarrative: {
          methodology: String,
          years: {
            type: Map,
            of: new mongoose.Schema(
              {
                otherSources: String
              },
              {
                _id: false,
                minimize: false
              }
            )
          }
        },
        description: String,
        expenses: [
          {
            _id: false,
            description: String,
            category: String,
            years: {
              type: Map,
              of: Number
            }
          }
        ],
        fundingSource: {
          type: String,
          enum: ['HIE', 'HIT', 'MMIS', null]
        },
        name: String,
        outcomes: [
          {
            _id: false,
            outcome: String,
            metrics: [
              {
                _id: false,
                metric: String
              }
            ]
          }
        ],
        plannedEndDate: Date,
        plannedStartDate: Date,
        schedule: [
          {
            _id: false,
            endDate: Date,
            milestone: String
          }
        ],
        standardsAndConditions: {
          doesNotSupport: String,
          supports: String
        },
        statePersonnel: [
          {
            _id: false,
            title: String,
            description: String,
            years: {
              type: Map,
              of: new mongoose.Schema(
                {
                  amt: {
                    type: Number,
                    default: 0
                  },
                  perc: {
                    type: Number,
                    default: 0
                  }
                },
                {
                  _id: false,
                  minimize: false
                }
              )
            }
          }
        ],
        summary: String,
        quarterlyFFP: {
          type: Map,
          of: new mongoose.Schema(
            {
              1: quarterlyFFP,
              2: quarterlyFFP,
              3: quarterlyFFP,
              4: quarterlyFFP
            },
            {
              _id: false,
              minimize: false
            }
          )
        }
      }
    ],
    // Currently there are no inputs in activity schedule summary
    // but this should be used to follow the sections pattern
    // activityScheduleSummary: {},
    proposedBudget: {
      incentivePayments: {
        ehAmt: {
          type: Map,
          of: incentivePayment
        },
        ehCt: {
          type: Map,
          of: incentivePayment
        },
        epAmt: {
          type: Map,
          of: incentivePayment
        },
        epCt: {
          type: Map,
          of: incentivePayment
        }
      }
    },
    assurancesAndCompliances: {
      procurement: [federalCitation],
      recordsAccess: [federalCitation],
      softwareRights: [federalCitation],
      security: [federalCitation]
    }
  },
  {
    minimize: false
  }
);

const APD = mongoose.model('APD', apdSchema);

module.exports = APD;

you can also view our entire source code here

hasezoey commented 2 years ago

when is this error happening? because just simply pasting the provided schema and running it (without any connection or insertion) does not yield any errors

(NodeJS 18.7.0)

thetif commented 2 years ago

I'm getting the error every time I try to insert into the database but specifically when I try to seed our data. This was all working before I updated mongoose. I think the issue is related to the new subdocument path merging.

mongodb.js ```javascript require('../models'); // import all of the mongo models const mongoose = require('mongoose'); const logger = require('../logger')('mongoose'); const setup = () => new Promise((resolve, reject) => { logger.verbose('Setting up MongoDB connection'); const connectionString = process.env.MONGO_URL || 'mongodb://mongo:cms@mongo:27017/eapd?authSource=admin'; const dbName = process.env.MONGO_DATABASE || 'eapd'; mongoose.connection.on('connected', () => { logger.verbose('MongoDB connected'); resolve(); }); try { mongoose.connect(connectionString, { dbName }); } catch (err) { logger.error(`Error in MongoDB connection: ${err}`); reject(err); } }); const teardown = () => new Promise((resolve, reject) => { mongoose.connection.on('disconnected', () => { logger.verbose('MongoDB disconnected'); resolve(); }); try { mongoose.connection.close().then(resolve); } catch (err) { logger.error(`Error disconnecting to MongoDB: ${err}`); reject(err); } }); module.exports = { setup, teardown }; ```
apd-seeder.js ```javascript const { setup, teardown } = require('../../db/mongodb'); const { data: apdData } = require(`../${process.env.NODE_ENV}/apds`); // eslint-disable-line import/no-dynamic-require const logger = require('../../logger')('mongoose APD seeder'); const APD = require('../../models/apd'); const models = [APD]; const dropCollections = async () => { const dropPromises = models.map(model => model.collection.drop()); try { await Promise.all(dropPromises); } catch (e) { if (e.code === 26) { // eslint-disable-next-line no-console console.log(`Error dropping: ${e.message}`); } else { throw e; } } }; const populate = async ({ model, data }) => { const count = await model.countDocuments().exec(); if (count === 0) { logger.verbose( `Seeding ${model.collection.name} with ${data.length} records` ); return model.create(data); } logger.verbose( `Skipping ${model.collection.name} population, ${count} documents found` ); return false; }; // Connect to MongoDB via Mongoose exports.seed = async () => { try { logger.verbose(`Connecting to MongoDB to seed data`); await setup(); logger.verbose( `Dropping collections for ${models .map(model => model.collection.name) .join(', ')}` ); await dropCollections(); logger.verbose('Populating collections'); await populate({ model: APD, data: apdData }); logger.verbose('Disconnecting from MongoDB'); await teardown(); } catch (err) { logger.error(`Error seeding: ${err}`); } }; exports.drop = async () => { try { await setup(); logger.verbose( `Dropping collections for ${models .map(model => model.collection.name) .join(', ')}` ); await dropCollections(); logger.verbose('Disconnecting from MongoDB'); await teardown(); } catch (err) { logger.error(`Error seeding: ${err}`); } }; ```
data to seed: ```json5 const apd = { name: 'HITECH IAPD', years: ['2022', '2023'], apdOverview: { programOverview: "

The Department...

", narrativeHIT: '

Continued Operations of the Medicaid EHR Incentive Payment Program

\n

Participate in the CMS EHR incentive program and continue to administer payments to EPs and EHs through the remaining years of the program (2023).

', narrativeHIE: "

Tycho''s existing health information infrastructure...

", narrativeMMIS: "

Medicaid Claims Data Feed...

" }, keyStatePersonnel: { medicaidDirector: { name: 'Cornelius Fudge', email: 'c.fudge@ministry.magic', phone: '5551234567' }, medicaidOffice: { address1: '100 Round Sq', address2: '', city: 'Cityville', state: 'AK', zip: '12345' }, keyPersonnel: [ { name: 'James Holden', position: 'HIT Coordinator', email: 'JimPushesButtons@tycho.com', isPrimary: true, fte: { 2022: 1, 2023: 1 }, hasCosts: true, costs: { 2022: 100000, 2023: 100000 } }, { name: 'Fred Johnson', position: 'Project Management Office Director', email: 'FJohnson@tycho.com', isPrimary: false, fte: { 2022: 0.3, 2023: 0.3 }, hasCosts: false, costs: { 2022: 0, 2023: 0 } } ] }, previousActivities: { previousActivitySummary: '

EHR Incentive Payment Program

', actualExpenditures: { 2019: { hithie: { federalActual: 140000, totalApproved: 280000 }, mmis: { 50: { federalActual: 23445, totalApproved: 82545 }, 75: { federalActual: 23440, totalApproved: 75340 }, 90: { federalActual: 235720, totalApproved: 262460 } } }, 2020: { hithie: { federalActual: 146346, totalApproved: 234526 }, mmis: { 50: { federalActual: 129387, totalApproved: 375445 }, 75: { federalActual: 413246, totalApproved: 654455 }, 90: { federalActual: 614544, totalApproved: 863455 } } }, 2021: { hithie: { federalActual: 320000, totalApproved: 540000 }, mmis: { 50: { federalActual: 0, totalApproved: 0 }, 75: { federalActual: 0, totalApproved: 0 }, 90: { federalActual: 0, totalApproved: 0 } } } } }, activities: [ { alternatives: '

Modifications to State Level Registry (SLR)...

', contractorResources: [ { description: 'Maintain SLR', end: '', hourly: { 2022: { hours: '', rate: '' }, 2023: { hours: '', rate: '' } }, useHourly: false, name: 'Super SLR Incorporated', start: '', totalCost: 32423, years: { 2022: 999756, 2023: 342444 } }, { description: 'Technology consulting and planning services.', end: '', hourly: { 2022: { hours: '', rate: '' }, 2023: { hours: '', rate: '' } }, useHourly: false, name: 'Tech Consulting Inc.', start: '', totalCost: 473573, years: { 2022: 333000, 2023: 200000 } } ], costAllocation: { 2022: { ffp: { federal: 90, state: 10 }, other: 105000 }, 2023: { ffp: { federal: 90, state: 10 }, other: 0 } }, costAllocationNarrative: { years: { 2022: { otherSources: '

No other funding is provided for this activity for FFY 2022.

' }, 2023: { otherSources: '

No other funding is provided for this activity for FFY 2023.

' } }, methodology: '

No cost allocation is necessary for this activity.

' }, description: '

III.A.1: Modifications to the State Level Repository

', expenses: [ { description: '', category: 'Training and outreach', years: { 2022: 40000, 2023: 40000 } }, { description: '', category: 'Travel', years: { 2022: 35000, 2023: 35000 } }, { description: '', category: 'Hardware, software, and licensing', years: { 2022: 700000, 2023: 0 } } ], fundingSource: 'HIT', outcomes: [ { outcome: 'Accept attestations for 2022, and modify SLR to meet new spec sheets released by CMS.', metrics: [ { metric: 'Complete SLR modifications by 11/1/21' }, { metric: 'Accept attestations through 4/30/22.' } ] }, { outcome: 'Provide support to EPs and EHs through attestation process.', metrics: [ { metric: "Guidance available on Tycho''s websites" }, { metric: 'Office hours availble for EPs and EHs' }, { metric: 'Site visits, as needed, for EPs and EHs' } ] } ], name: 'Program Administration', plannedEndDate: '2023-09-30', plannedStartDate: '2017-10-01', schedule: [ { endDate: '2020-09-07', milestone: 'Implementation of Final Rule and Stage 3 System Developments' }, { endDate: '2019-12-31', milestone: 'Environmental Scan Completion' }, { endDate: '2022-05-30', milestone: 'HIT Roadmap Development' } ], standardsAndConditions: { doesNotSupport: '', supports: '

We will comply with standards and conditions

' }, statePersonnel: [ { title: 'Project Assistant', description: 'Coordination and document management support daily administrative support such as meeting minutes and scribe, manages project library, scheduling, and correspondence tracking.', years: { 2022: { amt: 86000, perc: 1 }, 2023: { amt: 88000, perc: 1 } } }, { title: 'EHR Incentive Program Meaningful Use Coordinator (Research Analyst III)', description: 'Develop and monitor reports, assist data users in developing and managing queries.', years: { 2022: { amt: 101115, perc: 1 }, 2023: { amt: 102111, perc: 1 } } }, { title: 'IT Liaison', description: 'Provide analysis and coordination activities between the HIT Program Office and the IT section, to ensure that adequate resources and priority are established to complete the technology projects as identified.', years: { 2022: { amt: 101000, perc: 1 }, 2023: { amt: 104000, perc: 1 } } }, { title: 'Accountant III', description: 'Coordinate program state and federal budget and expense reporting, review and validate charges to CMS federal reports.', years: { 2022: { amt: 101000, perc: 3 }, 2023: { amt: 109000, perc: 3 } } }, { title: 'Public Information Officer', description: 'Develop outreach materials including: written, television and radio publications to support outreach for the Medicaid EHR Incentive Program', years: { 2022: { amt: 165000, perc: 0.5 }, 2023: { amt: 170000, perc: 0.5 } } }, { title: 'Systems Chief', description: 'Coordinate office resources, manage staff, budget, and resource assignments, and report program status.', years: { 2022: { amt: 135000, perc: 0.5 }, 2023: { amt: 140000, perc: 0.5 } } }, { title: 'Medicaid EHR Incentive Program Manager (Medical Assistance Administrator III)', description: 'Data collection and analysis, reporting, planning, service delivery modification, support administration of the EHR Incentive Payment Program including provider application review.', years: { 2022: { amt: 110012, perc: 1 }, 2023: { amt: 111102, perc: 1 } } }, { title: 'System Analyst (Analyst Programmer IV)', description: 'Supports design, development and implementation of information technology infrastructure for the projects/programs under the IT Planning office supported by this Implementation Advanced Planning Document.', years: { 2022: { amt: 98987, perc: 4 }, 2023: { amt: 99897, perc: 4 } } } ], summary: '1 Continued Operations of the Medicaid EHR Incentive Payment Program, includes modifications to the SLR, HIT staff, auditing, outreach, and non-personnel expenses for administering the program.', quarterlyFFP: { 2022: { 1: { combined: 25, contractors: 25, inHouse: 25 }, 2: { combined: 25, contractors: 25, inHouse: 25 }, 3: { combined: 25, contractors: 25, inHouse: 25 }, 4: { combined: 25, contractors: 25, inHouse: 25 } }, 2023: { 1: { combined: 25, contractors: 25, inHouse: 25 }, 2: { combined: 25, contractors: 25, inHouse: 25 }, 3: { combined: 25, contractors: 25, inHouse: 25 }, 4: { combined: 25, contractors: 25, inHouse: 25 } } } }, { alternatives: "

Medicaid Claims Data Feed to the HIE

", contractorResources: [ { description: 'Hosting and development support.', end: '', hourly: { 2022: { hours: '', rate: '' }, 2023: { hours: '', rate: '' } }, useHourly: false, name: 'Interface Vendor Inc.', start: '', totalCost: 26453574, years: { 2022: 650000, 2023: 750000 } }, { description: 'Interface M&O contractor.', end: '', hourly: { 2022: { hours: '', rate: '' }, 2023: { hours: '', rate: '' } }, useHourly: false, name: 'TBD', start: '', totalCost: 7398, years: { 2022: 0, 2023: 1000000 } } ], costAllocation: { 2022: { ffp: { federal: 90, state: 10 }, other: 0 }, 2023: { ffp: { federal: 75, state: 25 }, other: 0 } }, costAllocationNarrative: { years: { 2022: { otherSources: '

No other funding is provided for this activity for FFY 2022.

' }, 2023: { otherSources: '

No other funding is provided for this activity for FFY 2023.

\n' } }, methodology: '

No cost allocation is necessary for this activity.

\n' }, description: "

III.B.3 Medicaid Claims Data Feed to the HIE

", expenses: [ { description: '', category: 'Travel', years: { 2022: 0, 2023: 0 } } ], fundingSource: 'MMIS', outcomes: [ { outcome: 'Build interface between the MMIS Data Warehouse (DW) and the HIE so that Medicaid claims data can be made available to consumers in their Personal Health Record (PHR) within the HIE.', metrics: [ { metric: 'Hire contracted support to build an open API for the DW that the HIE and PHR can consume.' }, { metric: 'Provide support for using open API for DW' } ] } ], name: 'Claims Data Analytics', plannedEndDate: '2022-09-30', plannedStartDate: '2019-10-01', schedule: [ { endDate: '2022-12-31', milestone: 'Implement MMIS-HIE Interface' }, { endDate: '2022-12-31', milestone: 'Develop MMIS-HIE Interface Requirements' } ], standardsAndConditions: { doesNotSupport: 'We will comply with standards and conditions', supports: '

We will comply with standards and conditions

' }, statePersonnel: [ { title: 'Project Assistant', description: 'Assist with stuff', years: { 2022: { amt: 98000, perc: 1 }, 2023: { amt: 99000, perc: 1 } } }, { title: 'MMIS Project Manager', description: 'This position is responsible for the program development, planning, coordination, evaluation, independent management and oversight of the Tycho Automated Info', years: { 2022: { amt: 140000, perc: 1 }, 2023: { amt: 144000, perc: 1 } } }, { title: 'MMIS Trainer', description: 'Under the direct supervision of the Project Manager, this position is responsible for the development of a comprehensive training and support program for the Tycho Automated Information Management System', years: { 2022: { amt: 115000, perc: 1 }, 2023: { amt: 115000, perc: 1 } } }, { title: 'Programmer IV', description: 'The main purpose of this position is to develop and support Web and Client/Server applications. Duties include analysis, design, testing, debugging, documenting and supporting new and existing systems', years: { 2022: { amt: 140000, perc: 1 }, 2023: { amt: 145000, perc: 1 } } }, { title: 'Security IT', description: 'Make sure its secure.', years: { 2022: { amt: 115000, perc: 1 }, 2023: { amt: 120000, perc: 1 } } }, { title: 'Operations Specialist', description: 'Run the day to day.', years: { 2022: { amt: 125000, perc: 1 }, 2023: { amt: 130000, perc: 1 } } }, { title: 'Programmer V', description: 'The main purpose of this position is to develop and support Web and Client/Server applications. Duties include analysis, design, testing, debugging, documenting and supporting new and existing systems', years: { 2022: { amt: 150000, perc: 2 }, 2023: { amt: 155000, perc: 3 } } }, { title: 'Programmer III', description: 'The main purpose of this position is to develop and support Web and Client/Server applications. Duties include analysis, design, testing, debugging, documenting and supporting new and existing systems', years: { 2022: { amt: 120000, perc: 1 }, 2023: { amt: 125000, perc: 1 } } } ], summary: 'To provide healthcare statistical information and support MU, Tycho plans to interface the MMIS Data Warehouse (DW) to the HIE so that Medicaid claims data can be made available to consumers in their Personal Health Record (PHR) within the HIE. ', quarterlyFFP: { 2022: { 1: { combined: 25, contractors: 25, inHouse: 25 }, 2: { combined: 25, contractors: 25, inHouse: 25 }, 3: { combined: 25, contractors: 25, inHouse: 25 }, 4: { combined: 25, contractors: 25, inHouse: 25 } }, 2023: { 1: { combined: 25, contractors: 25, inHouse: 25 }, 2: { combined: 25, contractors: 25, inHouse: 25 }, 3: { combined: 25, contractors: 25, inHouse: 25 }, 4: { combined: 25, contractors: 25, inHouse: 25 } } } }, { alternatives: '

Health Information Exchange

\n

Maintain existing system.

, contractorResources: [ { description: 'Creates materials for training ', end: '2022-05-31', hourly: { 2022: { hours: '', rate: '' }, 2023: { hours: '', rate: '' } }, useHourly: false, name: 'Sample Training Contractor Name', start: '2022-01-01', totalCost: 20000, years: { 2022: 0, 2023: 0 } } ], costAllocation: { 2022: { ffp: { federal: 90, state: 10 }, other: 0 }, 2023: { ffp: { federal: 90, state: 10 }, other: 0 } }, costAllocationNarrative: { years: { 2022: { otherSources: '' }, 2023: { otherSources: '' } }, methodology: '' }, description: "

III.D. Statewide HIE Enhancement, Onboarding, and Support of Statewide HIE Operational Strategic Plan

", expenses: [ { description: 'Training materials creation and software for compliance', category: 'Hardware, software, and licensing', years: { 2022: 10000, 2023: 10000 } } ], fundingSource: 'HIE', outcomes: [ { outcome: 'Onboard 100 providers.', metrics: [{ metric: '100 providers onboarded.' }] } ], name: 'HIE Enhancement and Onboarding', plannedEndDate: '2023-09-30', plannedStartDate: '2018-01-01', schedule: [ { endDate: '2022-09-30', milestone: 'Onboard providers to assistance program' }, { endDate: '2022-12-31', milestone: 'Development of Roadmap' }, { endDate: '2023-01-01', milestone: 'HIE Staff Augmentation' }, { endDate: '2022-01-01', milestone: 'Modules for Care Coordination' }, { endDate: '2023-09-30', milestone: 'Provider Onboarding' }, { endDate: '2022-10-01', milestone: 'EDIE System Implementation' }, { endDate: '2022-12-31', milestone: 'Develop myAlaska HIE Authentication Requirements' }, { endDate: '2022-03-31', milestone: 'Completion of requirements gathering to prepare to receive ELR' }, { endDate: '2022-12-31', milestone: 'Configuration of internal BizTalk HL7 processes to translate the HL7 messages to PRISM' }, { endDate: '2022-09-30', milestone: 'Onboard Lab Providers' }, { endDate: '2018-12-31', milestone: 'Establishment of program requirements and outreach strategy' } ], standardsAndConditions: { doesNotSupport: '', supports: '

We will comply with standards and conditions

' }, statePersonnel: [ { title: 'Services Integration Architect/ Programmer (Analyst Programmer V)', description: 'Lead technical architecture design and development efforts for designing, implementing and maintaining services integrations leveraging resources such as the MCI, MPI and state HIE along with other DHSS Business Systems.', years: { 2022: { amt: 115000, perc: 4 }, 2023: { amt: 119000, perc: 4 } } } ], summary: 'Statewide HIE enhancement and onboarding.', quarterlyFFP: { 2022: { 1: { combined: 25, contractors: 25, inHouse: 25 }, 2: { combined: 25, contractors: 25, inHouse: 25 }, 3: { combined: 25, contractors: 25, inHouse: 25 }, 4: { combined: 25, contractors: 25, inHouse: 25 } }, 2023: { 1: { combined: 25, contractors: 25, inHouse: 25 }, 2: { combined: 25, contractors: 25, inHouse: 25 }, 3: { combined: 25, contractors: 25, inHouse: 25 }, 4: { combined: 25, contractors: 25, inHouse: 25 } } } }, { alternatives: '

Medicaid PHR/Blue Button

', contractorResources: [ { description: '', end: '', hourly: { 2022: { hours: '', rate: '' }, 2023: { hours: '', rate: '' } }, useHourly: false, name: 'RFP Planning Vendor Inc.', start: '', totalCost: 68734, years: { 2022: 50000, 2023: 5000 } }, { description: '', end: '', hourly: { 2022: { hours: '', rate: '' }, 2023: { hours: '', rate: '' } }, useHourly: false, name: 'Blue Button Builder Inc.', start: '', totalCost: 1235246, years: { 2022: 735246, 2023: 500000 } } ], costAllocation: { 2022: { ffp: { federal: 90, state: 10 }, other: 15000 }, 2023: { ffp: { federal: 90, state: 10 }, other: 0 } }, costAllocationNarrative: { years: { 2022: { otherSources: '

Sample Grant Related to Blue Button $15000

' }, 2023: { otherSources: '' } }, methodology: '' }, description: '

III.C.1 Medicaid Personal Health Record (PHR)/Blue Button Initiative

', expenses: [ { description: '', category: 'Hardware, software, and licensing', years: { 2022: 0, 2023: 0 } } ], fundingSource: 'HIE', outcomes: [ { outcome: 'Build blue button.', metrics: [{ metric: 'Test blue button with 10 providers.' }] } ], name: 'Medicaid Blue Button', plannedEndDate: '2022-09-30', plannedStartDate: '2018-06-01', schedule: [ { endDate: '2022-04-01', milestone: 'PHR/Blue Button HIE Build' }, { endDate: '2022-12-31', milestone: 'Blue Button Implementation' }, { endDate: '2022-12-31', milestone: 'On-Boarding of PHR/Blue Button Participants' } ], standardsAndConditions: { doesNotSupport: '', supports: '' }, statePersonnel: [ { title: '', description: '', years: { 2022: { amt: 0, perc: 0 }, 2023: { amt: 0, perc: 0 } } } ], summary: 'DHSS is requesting HITECH funding to support the onboarding of Medicaid recipients to the developed personal health record (PHR) available within the HIE.', quarterlyFFP: { 2022: { 1: { combined: 25, contractors: 25, inHouse: 25 }, 2: { combined: 25, contractors: 25, inHouse: 25 }, 3: { combined: 25, contractors: 25, inHouse: 25 }, 4: { combined: 25, contractors: 25, inHouse: 25 } }, 2023: { 1: { combined: 25, contractors: 25, inHouse: 25 }, 2: { combined: 25, contractors: 25, inHouse: 25 }, 3: { combined: 25, contractors: 25, inHouse: 25 }, 4: { combined: 25, contractors: 25, inHouse: 25 } } } } ], proposedBudget: { incentivePayments: { ehAmt: { 2022: { 1: 0, 2: 0, 3: 0, 4: 0 }, 2023: { 1: 0, 2: 0, 3: 0, 4: 0 } }, ehCt: { 2022: { 1: 0, 2: 0, 3: 0, 4: 0 }, 2023: { 1: 0, 2: 0, 3: 0, 4: 0 } }, epAmt: { 2022: { 1: 0, 2: 0, 3: 0, 4: 0 }, 2023: { 1: 0, 2: 0, 3: 0, 4: 0 } }, epCt: { 2022: { 1: 0, 2: 0, 3: 0, 4: 0 }, 2023: { 1: 0, 2: 0, 3: 0, 4: 0 } } } }, assurancesAndCompliances: { procurement: [ { title: '42 CFR Part 495.348', checked: true, explanation: '' }, { title: 'SMM Section 11267', checked: true, explanation: '' }, { title: '45 CFR 95.613', checked: true, explanation: '' }, { title: '45 CFR 75.326', checked: true, explanation: '' } ], recordsAccess: [ { title: '42 CFR Part 495.350', checked: true, explanation: '' }, { title: '42 CFR Part 495.352', checked: true, explanation: '' }, { title: '42 CFR Part 495.346', checked: true, explanation: '' }, { title: '42 CFR 433.112(b)', checked: true, explanation: '' }, { title: '45 CFR Part 95.615', checked: true, explanation: '' }, { title: 'SMM Section 11267', checked: true, explanation: '' } ], softwareRights: [ { title: '42 CFR 495.360', checked: false, explanation: 'We were able to get better pricing if we allowed the vendor to maintain ownership of the product they developed.' }, { title: '45 CFR 95.617', checked: true, explanation: '' }, { title: '42 CFR Part 431.300', checked: true, explanation: '' }, { title: '42 CFR Part 433.112', checked: true, explanation: '' } ], security: [ { title: '45 CFR 164 Security and Privacy', checked: true, explanation: '' } ] } }; const apdNoActivities = { name: 'HITECH IAPD No Activities', years: ['2022', '2023'], apdOverview: { programOverview: "

The Department is the state agency that administers...

", narrativeHIT: '

Continued Operations of the Medicaid EHR Incentive Payment Program

', narrativeHIE: "

Tycho''s existing health information infrastructure...

", narrativeMMIS: "

Medicaid Claims Data Feed to the HIE

" }, keyStatePersonnel: { medicaidDirector: { name: 'Cornelius Fudge', email: 'c.fudge@ministry.magic', phone: '5551234567' }, medicaidOffice: { address1: '100 Round Sq', address2: '', city: 'Cityville', state: 'AK', zip: '12345' }, keyPersonnel: [ { name: 'James Holden', position: 'HIT Coordinator', email: 'JimPushesButtons@tycho.com', isPrimary: true, fte: { 2022: 1, 2023: 1 }, hasCosts: true, costs: { 2022: 100000, 2023: 100000 } }, { name: 'Fred Johnson', position: 'Project Management Office Director', email: 'FJohnson@tycho.com', isPrimary: false, fte: { 2022: 0.3, 2023: 0.3 }, hasCosts: false, costs: { 2022: 0, 2023: 0 } } ] }, previousActivities: { previousActivitySummary: '

EHR Incentive Payment Program

', actualExpenditures: { 2019: { hithie: { federalActual: 140000, totalApproved: 280000 }, mmis: { 50: { federalActual: 23445, totalApproved: 82545 }, 75: { federalActual: 23440, totalApproved: 75340 }, 90: { federalActual: 235720, totalApproved: 262460 } } }, 2020: { hithie: { federalActual: 146346, totalApproved: 234526 }, mmis: { 50: { federalActual: 129387, totalApproved: 375445 }, 75: { federalActual: 413246, totalApproved: 654455 }, 90: { federalActual: 614544, totalApproved: 863455 } } }, 2021: { hithie: { federalActual: 320000, totalApproved: 540000 }, mmis: { 50: { federalActual: 0, totalApproved: 0 }, 75: { federalActual: 0, totalApproved: 0 }, 90: { federalActual: 0, totalApproved: 0 } } } } }, activities: [], proposedBudget: { incentivePayments: { ehAmt: { 2022: { 1: 0, 2: 0, 3: 0, 4: 0 }, 2023: { 1: 0, 2: 0, 3: 0, 4: 0 } }, ehCt: { 2022: { 1: 0, 2: 0, 3: 0, 4: 0 }, 2023: { 1: 0, 2: 0, 3: 0, 4: 0 } }, epAmt: { 2022: { 1: 0, 2: 0, 3: 0, 4: 0 }, 2023: { 1: 0, 2: 0, 3: 0, 4: 0 } }, epCt: { 2022: { 1: 0, 2: 0, 3: 0, 4: 0 }, 2023: { 1: 0, 2: 0, 3: 0, 4: 0 } } } }, assurancesAndCompliances: { procurement: [ { title: '42 CFR Part 495.348', checked: true, explanation: '' }, { title: 'SMM Section 11267', checked: true, explanation: '' }, { title: '45 CFR 95.613', checked: true, explanation: '' }, { title: '45 CFR 75.326', checked: true, explanation: '' } ], recordsAccess: [ { title: '42 CFR Part 495.350', checked: true, explanation: '' }, { title: '42 CFR Part 495.352', checked: true, explanation: '' }, { title: '42 CFR Part 495.346', checked: true, explanation: '' }, { title: '42 CFR 433.112(b)', checked: true, explanation: '' }, { title: '45 CFR Part 95.615', checked: true, explanation: '' }, { title: 'SMM Section 11267', checked: true, explanation: '' } ], softwareRights: [ { title: '42 CFR 495.360', checked: false, explanation: 'We were able to get better pricing if we allowed the vendor to maintain ownership of the product they developed.' }, { title: '45 CFR 95.617', checked: true, explanation: '' }, { title: '42 CFR Part 431.300', checked: true, explanation: '' }, { title: '42 CFR Part 433.112', checked: true, explanation: '' } ], security: [ { title: '45 CFR 164 Security and Privacy', checked: true, explanation: '' } ] } }; const data = [ { stateId: 'ak', status: 'draft', ...apd }, { stateId: 'ak', status: 'draft', ...apdNoActivities } ]; module.exports = { data, apd }; ```
hasezoey commented 2 years ago

Can reproduce

Reproduction Repository / branch: https://github.com/typegoose/typegoose-testing/tree/mongooseGh12220

Code ```ts // NodeJS: 18.7.0 // MongoDB: 5.0 (Docker) // Typescript 4.7.4 import * as mongoose from 'mongoose'; // mongoose@6.5.1 const nestedSchema = new mongoose.Schema({ 1: { type: Number, default: 0, }, }); const topSchema = new mongoose.Schema({ nestedPath1: { mapOfSchema: { type: Map, of: nestedSchema, }, }, }); const topModel = mongoose.model('topModel', topSchema); const data = { nestedPath1: { mapOfSchema: { // 2022: { 1: 0 }, // this data does not affect the error }, }, }; (async () => { await mongoose.connect(`mongodb://localhost:27017/`, { dbName: 'mongooseGh12220', }); await topModel.create(data); // error "RangeError: Maximum call stack size exceeded" await mongoose.disconnect(); })(); ```
Error Output ```txt /mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js:12 module.exports = function flattenObjectWithDottedPaths(obj) { ^ RangeError: Maximum call stack size exceeded at flattenObjectWithDottedPaths (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js:12:55) at flattenObjectWithDottedPaths (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js:36:5) at flattenObjectWithDottedPaths (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js:36:5) at flattenObjectWithDottedPaths (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js:36:5) at flattenObjectWithDottedPaths (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js:36:5) at flattenObjectWithDottedPaths (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js:36:5) at flattenObjectWithDottedPaths (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js:36:5) at flattenObjectWithDottedPaths (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js:36:5) at flattenObjectWithDottedPaths (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js:36:5) at flattenObjectWithDottedPaths (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js:36:5) ```

@thetif could you maybe add code-syntax highlighting to your code-blocks? Creating and highlighting code blocks also could you wrap your long code blocks in "Spoilers"? Details+Summary (Note: markdown needs one empty line between the last / next html element)

thetif commented 2 years ago

We can't upgrade past the vulnerable version of mongoose while this is an issue. Is there something we could do in the meantime? Is there something we should change in our code to get the newer versions working?

vkarpov15 commented 2 years ago

@thetif I'm sorry for the trouble, we'll have a fix in 6.5.3 within the next 24 hours.

thetif commented 2 years ago

That's awesome! Thanks so much for handling this so quickly.