Meteor - Quick Tips #4

Filtering Differences between Minimongo and Mongo

Minimongo is Meteor’s client-side implementation of Mongodb, while Mongodb is refer to as Mongo.

In Mongo, when limiting the fields of the return documents, there are two parameters. Minimongo also takes two parameters, but the second parameter needs a field wrapper to denote the fields to return.

Cut Down Documents Field Return
1
2
3
4
5
//Mongodb
CollectionName.find({}, {'onlyThisField':1});

//Minimongo
CollectionName.find({}, {fields: {'onlyThisField':1}});

Return Template in Template Helper

Template helpers only return a string when outputting to the templates, so an object output is not possible. The closest thing to rendering a template out to another template is to use Blaze.toHTML. The spacebar template needs to have the triple braces for raw output to convert a string to an actual element.

Blaze Returns a Html String
1
2
3
4
5
6
7
8
9
10
11
12
//Rendered
Template.blank.onRendered(function(){
this.data.rv = new ReactiveVar("");
this.data.rv.set(Blaze.toHTML(Template.postInfo));
});

//Helpers
Template.post.helpers({
info: function() {
return Template.instance().data.rv.get();
}
});
Output the Html String
1
2
3
<template name="post">
<div class="reading">{{{info}}}</div>
</template>