Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

423
Visualizações
Creating a GET request that displays all reviews based on the item value of what they reviewed

I am currently working on making a GET request on my backend that maps out all reviews based on the item number attached to the review. I've made a few dummy reviews that share the same item number (but have different _id values) and am trying to figure out how to create this GET request.

I can get all reviews to map out in general but not by item number

My current code block is this and I'm getting the error

TypeError: Cannot read properties of undefined (reading 'get')

router.get("/:id", async (req, res) => {
  const populateQuery = [
    {
      path: "user",
      select: ["username"],
    },
    {
      path: "reviews",
      select: ["item"],
      populate: { path: "user", select: ["username"] },
    },
  ]
  const reviews = await Review.find({})
  response.json(reviews.map((review) => review.toJSON()))
})

An example review would be:

_id:615323ee97dc7d1960350e33

text:"This could've been worse but I'm glad they actually tried this time"

item:168


_id:615b95dfd6a4fc3814139ad4

text:"Delete this review and this game"

item:168


_id:615b968e9dafdbead0de3fde

text:"Witcher is amazing"

item:4062

Basically, I want the function to show the ones with item:168 mapped out and separate from the Witcher review.

My model schema for reviews is this

import mongoose from "mongoose"
const { ObjectId } = mongoose.Schema.Types

const reviewSchema = new mongoose.Schema(
  {
    text: {
      type: String,
      required: true,
      maxlength: 500,
    },
    author: {
      type: ObjectId,
      ref: "User",
    },
    created: {
      type: Date,
      default: Date.now,
    },
    item: {
      type: Number,
      required: true,
    }
  },
  { timestamps: true }
)

const Review = mongoose.model("Review", reviewSchema)

export default Review

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda