question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Express Array Validator fails when the array size increases 1000

See original GitHub issue

The express validator fails to read and validate elements of array if the array size increases 1000. We are validating the array elements as follows

 body('ids).optional().isArray(),
 body('ids.*').not().isEmpty().withMessage('Required')
    .trim().isAlphanumeric().withMessage('Alpha Numeric')
    .isLength({ min: 1, max: 10 }).withMessage('Max 10 Characters'),

Where ids would be an array like [‘T0001’,‘T0002’,‘T0003’,…,‘T1100’]. So now this array contains 1100 elements. But if we reduce the size of elements to 500 or 600 the above validation works perfectly. Is there a different way to validate array of large size?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
adarshmadrechacommented, Sep 1, 2020

@liqiang372 Thanks for your suggestions. Your direction pointed me in the right direction.

I think I have narrowed down the issue. Ref: stackoverflow.com/q/19917401 Ref: https://expressjs.com/en/4x/api.html#express.json

Just be setting express.json({limit:'3mb'}) fixed the issue which I was facing. Will be releasing the API in production server on weekend. Will update it here once I also test this in the production server.

1reaction
yogeshkudikalacommented, Sep 4, 2020

Setting express json config resolved the issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation for array returns error for only 1st item and ignores ...
Hi, I am using schema-validation with express-validator 4.3.0, using a jsonSchema.json file. Within the schema, there is an array of objects ...
Read more >
express-validator to validate parameter which is an array
If you are using express-validator, You can pass minimum / maximum length option to check whether Array is empty or exceeds a certain...
Read more >
17.7.0 API Reference - joi.dev
Validates a value against a schema and throws if validation fails where: ... length(item) - reutrn the length of an array or string,...
Read more >
Active Record Validations - Ruby on Rails Guides
Active Record ValidationsThis guide teaches you how to validate the state of objects ... It returns an array of all the error messages...
Read more >
5.x API - Express.js
toString() may fail in multiple ways, for example foo may not be there or may not be a ... This option can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found