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

170
Views
Incluir detalles del usuario al completar comentarios para una publicación con Mongoose/MongoDB

Actualmente tengo tres modelos Mongoose.

Correo

 const schema = new mongoose.Schema( { title: { type: String, required: true, }, desc: { type: String, required: true, }, content: { type: String, required: true, }, slug: { type: String, required: true, }, comments: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Comment' }], }, { timestamps: true } );

Comentario

 const schema = new mongoose.Schema( { content: { type: String, required: true, }, user: { type: mongoose.Schema.Types.ObjectId, required: true, ref: 'User', }, }, { timestamps: true } );

Usuario

 const schema = new mongoose.Schema( { handle: { type: String, required: true, }, thumbnail: { type: String, required: true, }, }, { timestamps: true } );

Cuando consulto una publicación específica en mi clase Manager con:

 static async getPost(slug: string) { return await BlogPostModel.findOne({ slug }).populate('comments'); }

Obtuve con éxito una respuesta JSON con lo siguiente:

 { "_id": "6176d19b1aecee2189bf458d", "title": "My New Blog Post", "desc": "This is going to be a post about my newest blog post", "content": "Lorem ipsum", "slug": "my-new-blog-post", "comments": [ { "_id": "6176d701b3b8d00a7042a4d6", "content": "What an amazing comment this is.", "user": "6176c5d0bec3c2b694c9a48e", "createdAt": "2021-10-25T16:10:41.619Z", "updatedAt": "2021-10-25T16:10:41.619Z", "__v": 0 }, { "_id": "6176d701b3b8d00a7042a4d6", "content": "Second best comment.", "user": "6176c5d0bec3c2b694b9a47f", "createdAt": "2021-10-25T16:10:41.619Z", "updatedAt": "2021-10-25T16:10:41.619Z", "__v": 0 }, ], "createdAt": "2021-10-25T15:47:39.160Z", "updatedAt": "2021-10-25T16:10:41.657Z", "__v": 2 }

Mi pregunta es, ¿cómo haría para completar los datos del usuario en cada comentario, en lugar de que solo la identificación del objeto esté allí?

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!