Returning an undefined aggregate of the Meteor.js collection is not a function

I am trying to build in my Meteor.js application as shown below, but every time I call my logSummary method, I get the following error. Can someone please tell me what I am doing wrong / how to resolve this error? Thank.

Note. I am using the Meteor-aggregate package

TypeError: undefined is not a function
    at Object.Template.detailedreport.helpers.myCollection (http://localhost:3000/client/views/report.js?

the code:

Template.detailedreport.rendered = function() {
     Session.set("dreport_customer", "");
     Session.set("dreport_project", "");
     Session.set("dreport_startDate", new Date());
     Session.set("dreport_endDate", new Date());

   $('.set-start-date').datetimepicker({
        pickTime: false,
        defaultDate: new Date()
   });
   $('.set-end-date').datetimepicker({
        pickTime: false,
        defaultDate: new Date()
   });  

  $('.set-start-date').on("dp.change",function (e) {
       Session.set("dreport_startDate", $('.set-start-date').data('DateTimePicker').getDate().toLocaleString());
    });
    $('.set-end-date').on("dp.change",function (e) {
        Session.set("dreport_endDate", $('.set-end-date').data('DateTimePicker').getDate().toLocaleString());
    });
};

Template.detailedreport.helpers({
    customerslist: function() {
       return Customers.find({}, {sort:{name: -1}});       
    },
    projectslist: function() { 
       return Projects.find({customerid: Session.get("dreport_customer")}, {sort:{title: -1}});       
    },
    myCollection: function () {
      var now  = Session.get("dreport_startDate");
      var then = Session.get("dreport_endDate");
      var custID = Session.get("dreport_customer");
      var projID = Session.get("dreport_project");
          Meteor.call('logSummary', now, then, projID, custID, function(error, data){
            if(error)
              return alert(error.reason);
            return data;
          });        

    },      
    settings: function () {
        return {
            rowsPerPage: 10,
            showFilter: true,
            showColumnToggles: false,
            fields: [
                { key: '0._id.day', label: 'Day' },
                { key: '0.totalhours', label: 'Hours Spent'}                           
            ]
        };
    }

});

Template.detailedreport.events({
   'submit form': function(e) {
      e.preventDefault();

  Session.set('dreport_endDate', $('.set-end-date').data('DateTimePicker').getDate().toLocaleString());
  Session.set('dreport_startDate', $('.set-start-date').data('DateTimePicker').getDate().toLocaleString());
  Session.set('dreport_project', $(e.target).find('[name=project]').val());
  Session.set('dreport_customer', $(e.target).find('[name=customer]').val());      

   },  
   'change #customer': function(e){
        Session.set("dreport_project", "");
    Session.set("dreport_customer", e.currentTarget.value);
   },
   'change #project': function(e){
    Session.set("dreport_project", e.currentTarget.value);
   }  
});



Template:

    <div>
      {{> reactiveTable class="table table-bordered table-hover" collection=myCollection settings=settings}}
    </div>




Server:

Meteor.methods({
  logSummary: function(startDate, endDate, projid, custid){
    var pipeline = [
      { $match: { date: { $gte: new Date(startDate), $lte: new Date(endDate) },
                  projectid: projid,
                  customerid: custid
                } 
      },
      { $group: {
            _id: { 
                "projectid": "$projectid",
                "day": { "$dayOfMonth": "$date" },
                "month": { "$month": "$date" },
                "year": { "$year": "$date" }
            },
            totalhours: {"$sum": "$hours"}
       }}
    ];
    return ProjectLog.aggregate(pipeline);;
  }
});
+4
source share
1 answer

Looking at the ReactiveTable documentation, it looks like you need to do something like:

Template.myTemplate.helpers({
    myCollection: function () {
        return myCollection;
    }
});

Where myCollection is the name of the Mongo / Meteor collection (e.g. BlogPosts) that you defined, for example. BlogPosts = new Mongo.Collection('blogPosts');

, undefined is not a function, , Meteor . , undefined. undefined ReactiveTable. ReactiveTable - myCollection.find(), undefined.find() , , , .

Meteor , data , .

Meteor.call onCreated, :

Template.myTemplate.onCreated(function () {
    Meteor.call('myFunction', 'my', 'params', function (err, result) {
        if (err) { 
            // do something about the error
        } else {
            Session.set('myData',result);
        }
    });
});

Template.myTemplate.helpers({
    myData: function () {
        Session.get('myData')
    }
});

ReactiveTable.

, , , , minimongo , , , , ReactiveTable.

+3

Source: https://habr.com/ru/post/1568553/


All Articles