Meteor - Quick Tips #4

05/16/2015, Sat
Categories: #JavaScript
Tags: #Meteorjs

Filtering Differences between Minimongo and Mongo

Minimongo is Meteor's client-side implementation of Mongodb, while Mongodb is referred 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

// 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

// 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 -->

<template name="post">
  <div class="reading">{{{info}}}</div>
</template>