Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'aggregate' does not exist in angular2-meteor #40

Open
kai-iak opened this issue Jan 26, 2017 · 7 comments
Open

'aggregate' does not exist in angular2-meteor #40

kai-iak opened this issue Jan 26, 2017 · 7 comments

Comments

@kai-iak
Copy link

kai-iak commented Jan 26, 2017

Installing package in angular2-meteor project does not work.

To reproduce:

  1. Start with some code from the Socially tutorial
  2. In Terminal Run:
    meteor npm install and meteor
  3. Add package:
    meteor add meteorhacks:aggregate
  4. Add the following code to server\publications\parties:
Meteor.publish('party', function(partyId: string) {
  var metrics = new Mongo.Collection('metrics');
var pipeline = [
  {$group: {_id: null, resTime: {$sum: "$resTime"}}}
];
var result = metrics.aggregate(pipeline);
  return Parties.find(buildQuery.call(this, partyId));
}); 

Error appears in the terminal:
server/imports/publications/parties.ts (13, 22): Property 'aggregate' does not exist on type 'Collection<{}>'.

@kai-iak kai-iak changed the title 'aggregate' does note exist in angular2-meteor 'aggregate' does not exist in angular2-meteor Jan 26, 2017
@michaelb-01
Copy link

I'm having the same problem, did you resolve this in the end?

@GuofuHuang
Copy link

I have the same issue. +1

@vdavi
Copy link

vdavi commented Apr 2, 2017

I'm having the same issue.

@mhewett
Copy link

mhewett commented May 30, 2017

Add this to the file that uses the function:

/// < reference path="..path../declarations.d.ts" / >

And put this in the declarations.d.ts file:

declare module Mongo {

interface Collection {
    aggregate(args:any, filter:any): Array<any>;
}

}

@hsynaksu
Copy link

hsynaksu commented Aug 3, 2017

I am still getting this error with Angular 4.
I put the code you provided to declarations.d.ts file like this:
declare module Mongo {
interface Collection<T> {
aggregate(args:any, filter:any): Array<any>;
}
}

I had to add <T> for Typescript to not give error.
And I added /// <reference path="..path../declarations.d.ts" /> to the file I am using aggregate but
I am still getting "Property 'aggregate' does not exist on type" error.

@davinciagf
Copy link

With angular4 (4.2.0-rc.2) and meteor 1.5.1, I add the meteorhacks:aggregate package. Unfortunately I have the following issue

.aggregate is not a function

I completed the *.d.ts file with

declare module Mongo { interface Collection<T> { aggregate(args:any, filter:any): Array<any>; } }

and I added the reference to this file /// <reference path="..path../declarations.d.ts" />.

I used the aggregate module like this:

Meteor.publish('items', function(options:any) { return Results.aggregate( [ { $match: { score: { $gt: 80 } } }, { $count: "passing_scores" } ] )

@romiohasan
Copy link

meteorhacks:aggregate is working for my angular2-meteor project, so I put the details below :

export const ProductDB = new MongoObservable.Collection('product');

declarations.d.ts file :

declare module '*';

declare module Mongo {
interface Collection {
    aggregate(args:any, filter:any): Array<any>;
}
}

My server-side script where I am using the aggregate function:


/// <reference path="/declarations.d.ts" />

import { Meteor } from 'meteor/meteor';

if (Meteor.isServer) {

  Meteor.methods({

    'getMinPrice'() {
       
              var op = [
                  {
                    $group:
                    {
                      _id: "$shopID",
                      minPrice: { $min: "$price" }
                    }
                  }
                ]
              let result = ProductDB.collection.aggregate(op);
    }

  }) //end meteor.method

}
//end if server

Hope this helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants