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

245
Views
cómo configurar el valor predeterminado de la variable dentro del objeto en el esquema Mongoose

tengo este esquema:

 const mongoose = require('mongoose') const schema = new mongoose.Schema({ itemDate: { type: String, required: true, }, itemName: { type: String, required: true, }, itemPrice: { type: Object, required: true, price: { type: String, required: true, }, currency: { type: String, default: 'USD', }, }, }) module.exports = mongoose.model('Item', schema)

y usando esta mutación para agregar un elemento:

 Mutation: { addItem: async (_, args) => { const { itemName, itemPrice } = args.itemInput let { itemDate } = args if (!itemDate) { itemDate = new Date() } const item = new Item({ itemDate, itemName, itemPrice }) await item.save() return item },

Sin embargo, al agregar un artículo, la moneda permanece nula, ¿qué me estoy perdiendo aquí? Puedo agregar la moneda en la mutación addItem:

 itemPrice.currency = 'USD'

sin embargo, debe haber una mejor manera, ¿no es así?

Gracias por tu contribución.

about 4 years ago · Juan Pablo Isaza
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!