I have tried to use meteorhacks:aggregate package and I would like to get the return result from aggregate.
Please help to verify my code which it does not work:
Registers.js
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { Table, Alert, Button } from 'react-bootstrap';
import { Meteor } from 'meteor/meteor';
import { createContainer } from 'meteor/react-meteor-data';
import { Registers } from '../../api/registers';
const XLSX = require('xlsx');
const handleRemove = (registerId) => {
if (confirm('Are you sure? This is permanent!')) {
Meteor.call('registers.remove', registerId, (error) => {
if (error) {
console.log(error.reason, 'danger');
} else {
console.log('success');
}
});
}
};
const gettotalAmount = () => {
Meteor.call('getAmount');
console.log(total);
};
const DSRegisters = ({ registers, totalCount, match, history }) => (
<div className="Registers">
<div className="page-header clearfix">
<h4>{gettotalAmount}</h4>
===Omitted===
);
DSRegisters.propTypes = {
registers: PropTypes.arrayOf(PropTypes.object).isRequired,
totalCount: PropTypes.number.isRequired,
match: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
};
export default createContainer(() => {
const subscription = Meteor.subscribe('registers');
return {
registers: Registers.find({}, { sort: { createdAt: 1 } }).fetch(),
totalCount: Registers.find({}).count(),
};
}, DSRegisters);
api/registers.js
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Registers = new Mongo.Collection('registers');
const XLSX = require('xlsx');
Meteor.methods({
'getAmount': function getsummaryamount(){
return Registers.aggregate(
{ $group: {
_id: null,
total: { $sum: '$amount' }}
}
);
},
=== Omitted ===