Using Native Queries
The pattern
interface Source<DocumentType> {
// ...find / count / aggregate / update / insert / remove
native<ResultType = DocumentType[]>(query: DbQuery | RepositoryQuery): Promise<ResultType>;
}Example — a MongoDB aggregation
import { RepositoryQuery } from '@soapjs/soap';
export interface UniverseStatRow {
_id: { universe: string; alignment: string };
count: number;
}
export class UniverseStatsAggregation extends RepositoryQuery<Record<string, unknown>[]> {
build(): Record<string, unknown>[] {
return [
{ $group: { _id: { universe: '$universe', alignment: '$alignment' }, count: { $sum: 1 } } },
{ $sort: { '_id.universe': 1, '_id.alignment': 1 } },
];
}
}How the MongoDB source dispatches the payload
Other databases
Guidelines
Last updated