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

254
Views
Mangosta modelo con variaciones

Estoy tratando de hacer un modelo de producto que tenga variantes múltiples y estas variantes tienen paquetes múltiples y cada paquete tiene un precio e imagen diferentes, por ejemplo:

Producto Ram y CPU

Cada uno tiene una variante diferente, por ejemplo: para Ram hay 16 gb que tiene un precio de 50 $ y 32 gb que tiene un precio del 100%, para CPU hay i7 e i5 y cada uno tiene un precio diferente, ¿cómo puedo crear? un modelo para el escenario.

 const ProductSchema = new Schema({ img:{ type:String, required:true }, name: [{ name:String, }], variants:[{ name:String, target:[{ name:String, img:String }], package:[{ name:String, price:Number }] }] })

intento hacer esto pero no funciono

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

0

Simplemente puede crear un modelo a partir del esquema y enviar a la matriz del paquete los datos relevantes:

 const ProductModel = new model('Product', ProductSchema); ... // name, and variants are arrays so they default to empty arrays, only 'img' is required const newProduct = new ProductModel({ img: 'http://balhblahimg.com/' }; const variant = { name: 'foo', target: [], package: [] }; ... ... variant.target.push({name: 'a', img: 'b'}); variant.package.push({name: 'i7', price: 54}); // Do manipulation on variant object, add to pacage and target... // and push it to the newProduct newProduct.name.push('boo'); newProduct.variants.push(variant); newProduct.save();
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!