Reputation: 13
i am trying to find product reviews , based on their product id from products collection,
Below is the code for finding that reviews that has id that matches product id , it is a nested object in reviewInfo object
const reviewid = req.params.product_id
reviewSchema.find({reviewInfo:{reviewId:reviewid}}).then((value,err) => {console.log(value)})
i also have provided an image of my review schema
all i am getting is empty array .image shows the reviewproduct schema structure
Upvotes: 0
Views: 229
Reputation: 405
I think you are passing the wrong filter.
You should use a filter,
{"reviewInfo.reviewId":reviewId}
so your code will be like,
const reviewid = req.params.product_id
reviewSchema.find({"reviewInfo.reviewId":reviewId}).then((value,err) => {console.log(value)})
Upvotes: 3
Reputation: 61
in this query it just want to find an object exactly like this :
{reviewId:reviewid}
your query should be like this :
const reviewid = req.params.product_id reviewSchema.find({'reviewInfo.reviewId':reviewid}}).then((value,err)
=> {console.log(value)})
Upvotes: 1