Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
How to use the doValidate method of mongoose?

I have the following schema

const mySchema = new mongoose.Schema({
   kind: {
      type: String,
      enum: { 
         values: ["dollar", "euro", "pound", "lira"],
         message: "only dollar, euro, pound or lira are allowed"
      }
      required: [true, "kind field is required"]
   }
   // ... other fields
})

I have the following code:

app.post("/route", async (req, res, next) => {
    // 🏁 write code here
})

I want to validate only one path from that schema, I don't to validate everything, I just want to validate one field, so what I did according to this git discussion is the following:

app.post("/route", async (req, res, next) => {
    // 🏁 
    await mySchema.path("kind").doValidate(req.body.kind)
})

but this did not work and I got the following error:

.../node_modules/mongoose/lib/schematype.js:1332
        fn(err);
        ^

TypeError: fn is not a function
    at .../node_modules/mongoose/lib/schematype.js:1332:9
    at processTicksAndRejections (node:internal/process/task_queues:78:11)

How can I use doValidate and get the benefit of it? and why there's no documentation on how to use it?

  • and is there a way I can promisify it?
about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda