Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
How to add an array of a specific length using mongoose.Schema in Node.js?

I'm working on a project and need an array value, when entered, to have an array length of at least 12. I've read through some of the documentation on their site and I haven't found anything yet so I thought it wouldn't hurt to post here while I continue searching.

This is an example of the code.

const schema = new mongoose.Schema({
Array: {
         type: Array,
         required: true,
       }
});

Any insights you have would be greatly appreciated! If there's something I could clarify better please let me know!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use validate() from mongoose while defining your schema.

const schema = new mongoose.Schema({
Array: {
         type: Array,
         required: true,
         validate : lengthMin12
       }
});


const lengthMin12 = (val) => {
return val.length >= 12;
}

PS : The above link is from the latest version, but validate is available for older mongoose versions too.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!