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

805
Views
Mongoose: CastError: la conversión a incrustado falló para el valor "{valor: 'x'}" en la ruta "elementos"

Después de actualizar a Mongoose 5.11.13, recibo el siguiente error cuando intento agregar un elemento a un subobjeto dentro de un documento.

 CastError: Cast to embedded failed for value "{ value: 'new item' }" at path "items" at model.Query.exec (D:\repos\pushbox\node_modules\mongoose\lib\query.js:4358:21) at model.Query.Query.then (D:\repos\pushbox\node_modules\mongoose\lib\query.js:4452:15) at processTicksAndRejections (internal/process/task_queues.js:97:5) { messageFormat: undefined, stringValue: `"{ value: 'new item' }"`, kind: 'embedded', value: "{ value: 'new item' }", path: 'items', reason: TypeError: this.ownerDocument(...).isSelected is not a function

Mi Schma principal se llama Card . Contiene un subobjeto/subdocumento llamado Property y se ve así:

 export const CardSchema = new mongoose.Schema({ title: { type: String, required: true, }, description: { type: String, default: '', }, // Checklists in a Card checklists: [{ title: { type: String, required: true, }, items: [{ name: String, select: Boolean, }], }], // Properties in a card properties: [{ name: { type: String, required: true, }, items: [{ value: { type: String, default: '' }, isSelected: { type: Boolean, default: false }, }], }], box: { type: ObjectId, ref: 'Box', }, }, { timestamps: { createdAt: true, updatedAt: true }, });

La consulta que se utiliza para insertar un nuevo item dentro de una property es:

 const newPropItem = await Card.findOneAndUpdate( { _id: cardId, 'properties._id': propertyId, }, { $push: { 'properties.$.items': { value: newItem.trim() }, }, }, { new: true, }, );

No tengo idea de por qué sucede esto, ya que tenemos una consulta similar para la Lista de Checklist y funciona. Intenté esta consulta dentro del shell de mongo y funcionó allí. ¿Podrían ayudarme a averiguar qué me estoy perdiendo exactamente?

Ah, e intenté investigar todo el TypeError: this.ownerDocument(...).isSelected is not a function , no tuve suerte para encontrar nada que pudiera ayudarme en mi caso

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

no puede usar isSelected en Schema como nombre de campo porque isSelected() internamente para verificar qué rutas necesitamos validar en mongoose, así que cambie el nombre del archivo a isSelect o ...

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!