Aggregate

Overview of aggregation API

get
Aggregate

https://api.codemash.io/:version/db/:collectionName/aggregate/:id
Gets many records by your aggregation pipeline. This endpoint accepts GET and POST methods.
Request
Response
Request
Path Parameters
version
required
string
A version of the API endpoint.
collectionName
required
string
The name of the collection to aggregate. Must match the collection specified in aggregate.
id
required
string
The ID of an aggregate.
Headers
Authorization
required
string
Secret API key which belongs to your project or user. Not required if using cookies with a session ID.
x-cm-projectid
required
string
Your project's ID. Can be passed as a query parameter.
Query Parameters
tokens
optional
object
Key-value pairs (string: string) of tokens to insert into your aggregate. More about tokens follow the link below.
Response
200: OK
Returns a list of records. Here singular quotes are used to avoid escaping double quotes.
{
"result": "[{ '_id': '5e37136bf59f3a3f940b99a4', 'name': 'John' }]",
}
.NET
Node
PHP
.NET
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
var aggregateOptions = new AggregateOptions {
Tokens = new Dictionary<string, string> { { "name", "John" } }
}
var aggregateResult = await service.AggregateAsync<PersonProjection>(
Guid.Parse("{AGGREGATE_ID}"),
aggregateOptions
);
Node
PHP
use Codemash\CodemashClient;
use Codemash\CodemashDb;
class CodemashService
{
protected CodemashDb $codemashDb;
protected string $collectionName = '{YOUR_COLLECTION_NAME}';
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
$client = new CodemashClient($secretKey, $projectId);
$this->codemashDb = new CodemashDb($client);
}
public function aggregate()
{
$responseData = $this->codemashDb->getAggregate([
'collectionName' => 'employees',
'id' => '{AGGREGATE_ID}',
]);
}
}

Check the docs on aggregation.