Aggregate
The code in every language
Each example is the inside of main, written in every language API Maker runs : pick yours in the tabs, and every page shows it from then on. The types a call takes (GetAll, DeepItem…) are those of am : from am import GetAll in Python, use am::GetAll; in Rust, import am.GetAll; in Java and Kotlin ; PHP and C# have them without an import, Go names them am.GetAll.
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(…) |