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

263
Views
Publicar solicitud de RESTful API dando UnhandledPromiseRejectionWarning: ValidationError: Falló la validación del producto: error

Estoy trabajando con esta API RESTful y quiero enviar una solicitud posterior al servidor para crear un documento en la base de datos. Para eso estoy usando el método model.create. Pero me sigue enviando el error en la consola UnhandledPromiseRejectionWarning: ValidationError: Product validation failed: seller: Please enter product seller, category: Please enter the product category, description: Please enter product description, name: Please enter product name . Estoy probando esto. dentro del cartero. ¿Hay algún error en mi código? Cómo puedo arreglar esto. Aquí está mi archivo app.js

 const express = require('express') const mongoose = require('mongoose') const bodyParser = require("body-parser"); const app = express() app.use(bodyParser.urlencoded({extended: true})); mongoose.connect('mongodb://localhost:27017/playDB', {useNewUrlParser: true, useUnifiedTopology: true}) const playSchema = new mongoose.Schema({ name: { type: String, required: [true, 'Please enter product name'], }, price : { type: Number, required: [true, 'Please enter product price'], }, description: { type: String, required: [true, 'Please enter product description'] }, category: { type: String, required: [true, 'Please enter the product category'], }, seller: { type: String, required: [true, 'Please enter product seller'] }, stock: { type: Number, required: [true, 'Please enter product stock'], } }) const Product = mongoose.model('Product', playSchema) //get all products app.route("/products") .post(async function(req, res, next){ const product = await Product.create(req.body); res.send({ success: true, product }) }) app.listen(3000, function(){ console.log('server is running') })

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

0

No hice express leer el formato express. Entonces por eso no funcionó

Todo lo que tuve que agregar fue app.use(express.json()) Luego funcionó

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!