sql >> Base de Datos >  >> NoSQL >> MongoDB

Cómo agregar reactivamente mongodb en meteorito

No tienes una colección del lado del cliente. Además, debe suscribirse antes de llamar a este asistente.

Prueba esto

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './main.html';

var clientReport = new Mongo.Collection('clientReport');

Meteor.subscribe("reportTotals");

Template.header.helpers({
    'tasks': function () {
        console.log("tasks helper called : ");     
        console.log(clientReport.find().fetch());
    },   
});

Tampoco necesita la canalización ni la ejecución automática en el código del servidor, intente esto:

AtmData = new Mongo.Collection('atmdata');

Meteor.startup(() => {
  // code to run on server at startup
/*     AtmData.insert({
        bottles_used: 123,
    }); */

});



Meteor.publish("reportTotals", function() {
// Remember, ReactiveAggregate doesn't return anything

    ReactiveAggregate(this, AtmData, [{
        // assuming our Reports collection have the fields: hours, books    
        $group: {
            '_id': null,
            'bottles_used': {
            // In this case, we're running summation. 
                $sum: '$bottles_used'
                // $sum: 1
            }
        }
        }], { clientCollection: "clientReport" });    
});