Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Creating a get request that displays all reviews based on the item value of what they reviewed
Post Flair (click to view more posts with a particular flair)
Post Body

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

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.

Currently getting the error of TypeError: Cannot read properties of undefined (reading 'get')

My model schema for reviews is this

UPDATE : Added this line and it gave me everything I needed

  const reviews = await Review.find({ item: { $in: [item] } })

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

Author
Account Strength
100%
Account Age
5 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,114
Link Karma
553
Comment Karma
8,165
Profile updated: 2 days ago
Posts updated: 1 month ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago