CampbellSoftwareSolutions / mongoose-id-validator

Mongoose plug in to validate ObjectID references point to valid existing documents.
Other
47 stars 26 forks source link

Crashes when using recursive schemas #19

Closed LuisTAC closed 7 years ago

LuisTAC commented 7 years ago

Like the title says, it crashes when using recursive schemas. The following code produces the error below.

Code:
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test', { useMongoClient: true });
mongoose.Promise = require('bluebird');

var idValidator = require('mongoose-id-validator');

var Tasks = new mongoose.Schema();
Tasks.add({
   title     : String
 , subtasks  : [Tasks]
});

Tasks.plugin(idValidator);
Error:
c:\(...)\test\node_modules\mongoose-id-validator\lib\id-validator.js:33
    schema.eachPath(function (path, schemaType) {
                                              ^
RangeError: Maximum call stack size exceeded
    at c:\(...)\test\node_modules\mongoose-id-validator\lib\id-validator.js:33:30
    at Schema.eachPath (c:\(...)\test\node_modules\mongoose\lib\schema.js:673:5)
    at IdValidator.validateSchema (c:\(...)\test\node_modules\mongoose-id-validator\lib\id-validator.js:33:12)
    at c:\(...)\node_modules\mongoose-id-validator\lib\id-validator.js:37:27
(last 3 lines repeated 4 more times)

Great plugin anyway.

martin-css commented 7 years ago

Thanks for the report. Version 0.4.3 has been published to NPM with a fix.