Want to get only reviews that belongs to product being clicked


#1

i have two collections and i want to show reviews only for product thats been clicked , but i am getting all reviews (from reviews collection) no matter what product i click.

Products = new Mongo.Collection("products");
Reviews = new Mongo.Collection("reviews");

for adding and reading reviews i have following code in router.js

   // Add new review
this.route('add_review', {
    path:'/add_review/:_id',
    template:'add_review',
    data: function(){
        return Products.findOne(this.params._id)
    }
});
// Read reviews
this.route('reviews', {
    path:'/reviews/:_id',
    template:'reviews',
    data: function(){
            return Products.findOne(this.params._id)
     }
  });
});

reviews.js

Template.reviews.helpers({
'reviews': function () {
    return Reviews.find( )}
  })

reviews.html (to read reviews )

<template name="reviews">
    <div class="row product-row">
        <div class="col-md-2">
            <img class="full" src="{{image}}">
        </div>
        <div class="col-md-10">
            <h4>{{name}}</h4>
            <p>{{description}}</p>
        </div>
    </div>
{{#each reviews}}
    <p>{{body}} </p>
{{/each}}   </template>

You can see the entire code here GitHub repository


#2

From what I see, you try to read all reviews. Not only the ones for a particular product.


#3

yes that is what i am asking.Have tried different things still not working.So can you help how to do that you can see entire code on my GitHub Repository too.


#4

you have gitignored .meteor/packages so I can’t even run you project :wink: fix it and I’ll take a look.


#5

Haha, I had the same problem when I tried to clone this project.


#6

Ah, btw. @soni1, provide some test data :smile:


#7

And while you’re at it, there’s also no place with collection schemas which we could easily check to know what’s what. We have to guess your database schema from parts of code in different folders all over the project. That makes it a lot of research just to fix a simple thing. Though my guess is just the part I pasted previously where you should find by a product instead of finding all reviews.