Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Rendering MongoDB documents with Meteor
{{> hello}}
<template name="hello">
{{#each projects}}
<p>Name: {{name}}</p>
{{#print personnel}}
<li>Name : {{name}}</li>
<li>Rank : {{rank}}</li>
Projects = new Meteor.Collection("projects");
Personel = new Meteor.Collection("personel");
if (Meteor.is_client) {
/** Create a helper that will iterate over each id in the object **/
Handlebars.registerHelper('print', function(context, options) {
var ret = "<ul>";
for(var i=0, j=context.length; i<j; i++) {
var pers = Personel.findOne({_id:context[i]});
ret = ret + options.fn(pers);//Pass the retrieved personel object to the handlerbars function
ret += "</ul>"
return ret;
Template.hello.projects = function(){
return Projects.find({});
var one = Personel.insert({name:"Lander",rank:"CEO"});
var two = Personel.insert({name:"Sander",rank:"CEO"});
var three = Personel.insert({name:"Tree",rank:"CEO"});
Projects.insert({name:"Project 1",personnel:[one,two]});
if (Meteor.is_server) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.