tingodb
tingodb copied to clipboard
Aggregate Framework Support
Aggregation support would be extremely awesome. :+1: Any plans to include it on the roadmap?
Probably so, original mongo db drive has simulation of aggregation thru map reduce, I believe we can adopt it.
Has there been any progress on this i.e so you can do db.collection.aggregate()
I am also interested in any news about support of aggregation :+1:
+1
+1
+1
+1
+1
+1
+1
+1
+1
Any update for aggregate support?
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 }]));
});
});
}