Aggregate
g.sys.db.aggregate calls the aggregate schema API of any table from your code, with the same headers and query parameters as over HTTP. It returns the data. The whole envelope (success, statusCode, data, totalCount, errors…) comes back when true is passed as the second argument in TypeScript, and through full in the other languages : g.sys.db.full (g.Sys.Db.Full in C# and Go, $g->sys->db->full in PHP).
Aggregation runs on MongoDB. aggregateQuery is a pipeline of MongoDB : every stage and operator of the MongoDB manual works, so this page shows three common shapes.
Group, filter and count : $group, $match¶
| MongoDB Basic aggregation | |
|---|---|
| MongoDB Basic aggregation | |
|---|---|
Several groupings at once : $facet and $bucket¶
Join another collection : $lookup¶
| MongoDB $lookup | |
|---|---|
Multi-tenant¶
instance: "crm::acme"works on the database of the tenantacmeof the multi-tenant instancecrm.- With
instance: "crm", the call works on the database of the tenant of the request: a custom API called with the x-am-tenant-username header passes it on to the APIs it calls. A request without a tenant works on the structure database.
| Aggregate the customers of the tenant acme (MongoDB) | |
|---|---|
| Aggregate the customers of the tenant acme (MongoDB) | |
|---|---|
Without a schema¶
g.sys.db.gen.aggregateGen takes the same arguments and calls the aggregate generated API : no schema, so the data is read and written as it is in the table, without the conversions, validations and defaults of the schema.
| Language | The call |
|---|---|
| TypeScript | g.sys.db.gen.aggregateGen(…) |
| Python | g.sys.db.gen.aggregate_gen(…) |
| PHP | $g->sys->db->gen->aggregateGen(…) |
| C#, Go | g.Sys.Db.Gen.AggregateGen(…) |
| Rust | g.sys.db.aggregate_gen(Aggregate::new(…)) |
| Java, Kotlin | g.sys.db.gen.aggregateGen(…) |