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

104
Views
¿Cómo completar un valor de propiedad con un objeto javascript en un objeto javascript?

digamos que tengo dos matrices:

 authors = [ { name: 'Robert Martin', id: "afa51ab0-344d-11e9-a414-719c6709cf3e", born: 1952, }, { name: 'Martin Fowler', id: "afa5b6f0-344d-11e9-a414-719c6709cf3e", born: 1963 } ]
 let books = [ { title: 'Clean Code', published: 2008, author: 'Robert Martin', id: "afa5b6f4-344d-11e9-a414-719c6709cf3e", genres: ['refactoring'] }, { title: 'Agile software development', published: 2002, author: 'Robert Martin', id: "afa5b6f5-344d-11e9-a414-719c6709cf3e", genres: ['agile', 'patterns', 'design'] }, { title: 'Refactoring, edition 2', published: 2018, author: 'Martin Fowler', id: "afa5de00-344d-11e9-a414-719c6709cf3e", genres: ['refactoring'] } ]

const Libro = require('./controladores/libro')

const Autor = require('./controladores/autor')

usando el esquema de objeto mongoose, la propiedad de autor del objeto de libro quiere completarse con el objeto de autor completo si libro.autor === autor.nombre.

como esto:

 { title: 'Clean Code', published: 2008, author: { name: 'Robert Martin', id: "afa51ab0-344d-11e9-a414-719c6709cf3e", born: 1952, }, id: "afa5b6f4-344d-11e9-a414-719c6709cf3e", genres: ['refactoring'] },

He intentado esto:

 books.forEach(book => { const bookAuthor = authors.find(author => book.author === author.name).name Book.findOne({author: bookAuthor}).populate('author') }

sin éxito, de alguna manera js es difícil de manipular la estructura de datos sobre la marcha que Python, siento. ¿Podrías ayudar?

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!