Meteor get Collections by Reference

This short code sample will show you how to get access to a Collection by reference.

The root variable is essentially referencing the this global but detects the correct global reference based on where the client is running.

var colData = function (collectionName) {

var root = Meteor.isClient ? window : global;

var col = root[collectionName];

return col.find().fetch();



Iron Router Multiple Data Context with Meteor

Here’s how to do it:

Router.route('/things', {

    name: 'things',    

    waitOn: function () {

        return [this.subscribe('thing'),this.subscribe('thinga')];


    data: function () {

        return {

            thing: Thing.find(),

            thinga: Thinga.findOne({type: "abc"})



    onAfterAction: function () {




To access the data context in the Template use the following syntax:

console.log('Template.instance().data.thinga.propertyname', Template.instance().data.thinga.propertyname);



Meteor Remote MongoDB

I don’t like to use big repeating command and I was searching for a solution where I will be setting a variable embedded with something so every time I start my meteor app; the MONGO_URL will set to environment automatically. So this what I did:

In the package.json file I replaced the start parameter as below:

"scripts": {
    "start": "MONGO_URL=mongodb://username:password@host_url:portnumber/dbname meteor run"



Fix: Error: Cannot find module ‘@babel/runtime/helpers/builtin/objectSpread’

Another common error:

Error: Cannot find module ‘@babel/runtime/helpers/builtin/interopRequireDefault’

How to fix:

This has been traced in the forums as an incompatibility with the latest version of @babel/runtime. Change the corresponding line in the package.json file

  "dependencies": {
    "@babel/runtime": "7.0.0-beta.55",

and then do

meteor npm install




Meteor template default events

Whenever you create a new template you can use these boilerplate events and rename them to fit your needs.

Template.templateName.onDestroyed(function (){


Template.templateName.onRendered(function () {





How to import from JSON file into Meteor

    // import data only when Products collection is empty

    if (Products.find().count() === 0) {
        console.log("Importing private/products.json to db")

        var data = JSON.parse(Assets.getText("products.json"));

        data.forEach(function (item, index, array) {