Hello.
I have the collection “menu” with structure:
{
"_id" : “vJQr7EuieDHMuX2nx” “section” : “vine” “price” : “200” “category” : “bar”
"_id" : “vJQr7EuieDHMuX4rf” “section” : “beer” “price” : “200” “category” : “kitchen”
"_id" : “vJQr7EuieDHMuX5tg” “section” : “milk” “price” : “200” “category” : “kbar”
"_id" : “vJQr7EuieDHMuX4sc” “section” : “beer” “price” : “200” “category” : “kitchen”
"_id" : “vJQr7EuieDHMuX2xs” “section” : “vine” “price” : “200” “category” : “bar”
}
I want to show the user only “section” without repeating
For this I used
Menu.aggregate([{$group:{_id:"$section"}}])
but it’s not working
How can I do this? May be to use a different method?
Server side:
Meteor.methods({
'getSections': function () {
var pipeline = [{$group:{_id:"$section"}}];
var result = Menu.aggregate(pipeline);
var sections = [];
for (i = 0; i < result.length; i++) {
sections.push(result[i]._id);
};
console.log(sections);
return sections;
}
});
result in the server: [ ‘vine’, ‘beer’, ‘milk’ ]
Client side:
Template.MobBarMenu.helpers({
'list': function(){
this.render('MobBarMenu', {});
},
'listSections': function () {
Meteor.call('getSections', function (err, data) {
console.log(data);
// return data;
});
}
});
template name="MobBarMenu"
{{#each listSections}}
{{this}}
{{/each}}
template
I don’t know where to find the solution