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

185
Views
Vue - ¿Cómo enviar una matriz de datos a Mongodb?
{ "product": [ { "product_ID": "test", "productDetail": "test", "income_ID": "6297343ec4cc7b1ca85521ba" }, { "product_ID": "test", "productDetail": "test", "income_ID": "6297343ec4cc7b1ca85521ba" } ] }

esta es mi matriz de datos. Usé axios enviar datos para expresar y mongodb pero no funciona

y este es mi codigo express para guardar datos en mongodb

 quotationRoute.route('/incomeProduct').post((req, res, next) => { var newProduct = new Qot({ product:product.req.body.product, }) newProduct.save(err => { if (err) { return res.status(400).json({ title: 'error', error: 'error' }) } return res.status(200).json({ title: 'signup success', id: newProduct._id }) })
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si tu esquema es el siguiente:

 { productDetail: "String", productQyt: "String", productPrice: "String", productUnit: "String", createdAt: { type: "Date", default: "Date.now", }, income_ID: { type: "mongoose.Schema.Types.ObjectId", ref: "Business", }, product_ID: "String", };

Y los datos que está enviando a su servidor son:

 { "product": [ { "product_ID": "test", "productDetail": "test", "income_ID": "6297343ec4cc7b1ca85521ba" }, { "product_ID": "test", "productDetail": "test", "income_ID": "6297343ec4cc7b1ca85521ba" } ] }

Tiene una matriz de objetos, por lo que parece que desea guardar varias citas para ese propósito, podría usar los métodos insertMany de mongoose

Aquí hay un ejemplo de cómo debe ser su código:

 quotationRoute.route('/incomeProduct').post(async (req, res, next) => { try { await Qot.insertMany(req.body.product); return res.status(200).json({ title: 'signup success', // id: newProduct._id as you save multiple Qot this will be unecessary }); } catch (e) { return res.status(400).json({ title: 'error', error: 'error', }); } });
over 4 years ago · Santiago Trujillo 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!