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

147
Views
MongoDB (mangosta) empujando a las matrices está ignorando las propiedades

Tengo un esquema de usuario que se ve así:

 reputation: [ { voter_id: { type: String, required: true, }, }, { score: { type: Number, required: true, }, }, { comment: { type: String, maxlength: 100, }, }, { voted_at: { type: Date, default: Date.now, }, }, ],

Cada vez que intento insertar un objeto en esta matriz como esta

 User.updateOne( { id: user.id }, { $push: { reputation: { voter_id: interaction.user.id, score: rating, comment, }, }, }, );

Solo la primera propiedad del objeto a enviar, aquí voter_id , se establece en la base de datos, aunque los otros valores no están indefinidos.

El objeto almacenado en la base de datos se ve así:

 { "_id" : ObjectId("61478043630ef626f50c9c2b"), "reputation" : [ { "voter_id" : "214772155114717184", "_id" : ObjectId("61478060630ef626f50c9c7c") } ], "__v" : 0 }

Faltan las propiedades. Para este ejemplo, la puntuación fue 1 y el comentario "prueba". ¿Cuál es el problema aquí?

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

0

La notación de matriz es lo que hace que los elementos se separen, debe ser un solo objeto:

 reputation: [ { voter_id: { type: String, required: true, }, score: { type: Number, required: true, }, comment: { type: String, maxlength: 100, }, voted_at: { type: Date, default: Date.now, }, } ]
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!