Meteor Blaze template not showing filtered Mongodb embedded collection -


i have following example of data set:

samplecol.insert({     name: "john doe",     description: "nice guy",     embedded_1: [{         key1: 'x1',         key2: 'x2',         tarifftypes: [{             tariffcode: 'promocional',             price: 125,             weekdays: ['sun', 'sat']                       },         {             tariffcode: 'lastminute',             price: 150,             weekdays: ['sun', 'sat']            }],          },         {         key1: 'x3',         key2: 'x4',            tarifftypes: [{                 tariffcode: 'promocional',                 price: 175,                 weekdays: ['sun', 'sat']                        },             {                 tariffcode: 'lastminute',                 price: 200,                 weekdays: ['sun', 'sat']             }]          }]     }); 

i trying filter , show on template embedded_1 key1='x1'. here template:

  <template name="test2">    {{#each items}}     {{# each embedded_1}}         {{this.key1}}     {{/each}}    {{/each}}    </template> 

i tried following , template helper versions:

version 1 returning both x1 , x3:

template.test2.helpers({   items: function () {      collection = samplecol.find({'embedded_1.key1': 'x1'});   return collection;   }  }); 

this returns results:

       collection = samplecol.find({embedded_1: {$elemmatch: { key1: 'x1'}}}); 

the exit in both cases is: x1x3

it should show x1.

where error?

edit: have followed answers suggested mark leiber , bravekenny , solve mongodb output . can on mogo shell desired outcome following command:

db.samplecol.find({},{_id:0, embedded_1: {$elemmatch: {key1:"x1"}}}) 

this solves mongo part. however, guess problem related on how results interact meteor blaze's template. template "test2" keeps showing entire collection rather filtered.

any hints there?

edit #2 indeed blaze template issue. mongo find() code above correctly returns key='x1' results. strips out parent document , data such name , description:

{   embedded_1: [{         key1: 'x1',         key2: 'x2',         tarifftypes: [{             tariffcode: 'promocional',             price: 125,             weekdays: ['sun', 'sat']                       },         {             tariffcode: 'lastminute',             price: 150,             weekdays: ['sun', 'sat']            }],          }; 

however, template shows result if written below, including {{#each items}} {{/each}} line

 <template name="test2">    {{#each items}}     {{name}} <br>     {{description}}<br>     {{#each embedded_1}}        {{this.key1}} <br>        {{#each tarifftypes}}             {{this.price}} <br>         {{/each}}    {{/each}} {{/each}} </template> 

despite template helper not returning name , description, show them on browser together. shows this:

john doe nice guy x1  125  150  x3  175  200  

i have tester taking out {{#each items}} or {{#each embedded_1}} , none worked.

how template blaze should written?

this should return embedded document:

samplecol.find({embedded_1: {$elemmatch:{key1:'x3'}}}, {fields: {embedded_1: true}}) 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -