tingodb icon indicating copy to clipboard operation
tingodb copied to clipboard

Aggregate Framework Support

Open ElliotChong opened this issue 11 years ago • 14 comments

Aggregation support would be extremely awesome. :+1: Any plans to include it on the roadmap?

ElliotChong avatar Nov 01 '13 06:11 ElliotChong

Probably so, original mongo db drive has simulation of aggregation thru map reduce, I believe we can adopt it.

sergeyksv avatar Nov 06 '13 13:11 sergeyksv

Has there been any progress on this i.e so you can do db.collection.aggregate()

dottodot avatar Jan 20 '15 10:01 dottodot

I am also interested in any news about support of aggregation :+1:

nicolasdugue avatar Jan 19 '16 11:01 nicolasdugue

+1

kgividen avatar Aug 16 '16 16:08 kgividen

+1

daaru00 avatar Nov 23 '16 11:11 daaru00

+1

sam-artuso avatar Jan 11 '17 12:01 sam-artuso

+1

Fohlen avatar Jan 26 '17 14:01 Fohlen

+1

thomas-rager avatar Mar 13 '17 23:03 thomas-rager

+1

Burry avatar May 07 '17 09:05 Burry

+1

moravcik avatar May 18 '17 21:05 moravcik

+1

IgorBaranov avatar Nov 07 '17 10:11 IgorBaranov

+1

pasalino avatar Nov 18 '18 20:11 pasalino

Any update for aggregate support?

ShongSu avatar Jun 24 '19 15:06 ShongSu

If it helps someone, I have a BaseModel class that has the following function, which works for my special test case:

  async aggregate(aggregations) {
    const [{ $sort }, ...rest] = aggregations;
    let steps = rest;
    const populates = [];
    while (steps[0].$lookup) {
      populates.push(steps[0]);
      steps = steps.slice(1);
    }
    const [
      { $match },
      {
        $facet: {
          stage2: [{ $skip }, { $limit }]
        }
      }
    ] = steps;
    const collection = await this._collection;
    const sort = Object.entries($sort).map(([key, value]) => [key, value]);
    return new Promise((resolve, reject) => {
      const found = collection.find($match).sort(sort);
      found.toArray((err, items) => {
        if (err) {
          return reject(err);
        }

        const count = items.length;
        items = items
          .filter((_item, index) => {
            return index >= $skip;
          })
          .filter((_item, index) => {
            return index < $limit;
          });
        let populatePromise = Promise.resolve([]);
        if (populates.length) {
          const paths = [populates.map(pop => ({ path: pop.$lookup.localField }))];
          const schema = this._schema;
          populatePromise = populateFields(items, paths, schema);
        }
        populatePromise.then(() => resolve([{ count, data: items }]));
      });
    });
  }

malixsys avatar Nov 25 '19 14:11 malixsys