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

423
Views
TypeError: la devolución de llamada no es una función en Timeout._onTimeout

Estoy tratando de guardar un documento en el validador de esquema mongodb asíncrono en node.js. Configuré un atributo llamado 'etiqueta' de validación personalizada en el esquema mongodb. El validador en 'etiqueta' es asíncrono. El programa agrega el documento en mongodb pero después de los 4 segundos (setTimeout()), da el error de que la devolución de llamada no es una función.

 const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/playground') .then(() => console.log('Connected with MongoDB...')) .catch(err => console.log("Couldn't connect with MongoDB!!!", err)); const courseSchema = new mongoose.Schema({ name: { type: String, required: true, minlength: 3, maxlength: 55 }, author: String, edition: Number, categories: { type: String, enum: ['web', 'mobile', 'research', 'networking'], required: true }, tags: { type: Array, validate: { isAsync: true, validator: function (v, callback) { setTimeout(() => { const result = v && v.length > 0; callback(result); }, 4000); }, message: 'A course should have at least one tags' } }, data: { type: Date, default: Date.now }, isPublished: Boolean, price: { type: Number, min: 5, max: 50, required: function () { return this.isPublished } } }); const Course = mongoose.model('Course', courseSchema); async function createCourse() { const course = new Course({ name: "Compiler Constructions", author: "Mudassir", edition: 2, categories: 'web', tags: ['CUI'], isPublished: false, price: 8 }); try { const result = await course.save(); console.log(result); } catch (err) { console.log(err.message); } } createCourse();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Basado en documentos y promesas , intente esto:

 tags: { type: Array, validate: { validator: function (v) { return new Promise((resolve) => { setTimeout(() => { const result = v && v.length > 0; resolve(result); }, 4000); }); }, message: 'A course should have at least one tags', }, },
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!