francescov1 / mongoose-tsgen

A plug-n-play Typescript generator for Mongoose.
105 stars 25 forks source link

Schema with more than 13 ObjectId property throws "Maximum call stack size exceeded" #35

Closed henaff closed 3 years ago

henaff commented 3 years ago

Hi, with a lot of schema with mongoose ^5.11.16, if i use more than 13 ObjectId in Types "RangeError: Maximum call stack size exceeded" is throwed. No matter the order or the file where they are placed.

image

francescov1 commented 3 years ago

Hi @henaff,

Have you tried using the newest version? Many of these niche issues have been fixed. The preferable solution would be to update to the latest version, but note that this requires Mongoose v5.11+. If you need to use a version of Mongoose lower than 5.11, you can update to mongoose-tsgen v6.0.10 with npm install mongoose-tsgen@6.0.10.

Let me know if the issue is still present after updating!

kurtcarpenter commented 3 years ago

Also getting "Maximum call stack size exceeded" with a slightly different example involving String defaults. Not sure if this has the same root cause as the original issue. mongoose@5.11.15 mongoose-tsgen@7.0.11

import mongoose from 'mongoose';

export default mongoose.model('foo', new mongoose.Schema({
  test: {
    type: {
      str: String
    },
    default: {
      str: 'something' // adding this property default causes the error
    }
  }
}));
francescov1 commented 3 years ago

@kurtcarpenter I have not seen that syntax for Mongoose schemas before. If you define your types at the source it should fix the issue:

import mongoose from 'mongoose';

export default mongoose.model('foo', new mongoose.Schema({
  test: {
     str: {
        type: String,
        default: 'something'
     }
  }
}));

Does your syntax work as expected with Mongoose? If so I will look to add support for it as well!

francescov1 commented 3 years ago

Closing this for housekeeping, feel free to re-open if this is still an issue!