MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / aggregate

Method aggregate

packages/mongodb/src/MongoConnection.ts:330–350  ·  view source on GitHub ↗
(
    entityName: EntityName<T>,
    pipeline: any[],
    ctx?: Transaction<ClientSession>,
    loggerContext?: LoggingOptions,
    signal?: AbortSignal,
  )

Source from the content-addressed store, hash-verified

328 }
329
330 async aggregate<T extends object = any>(
331 entityName: EntityName<T>,
332 pipeline: any[],
333 ctx?: Transaction<ClientSession>,
334 loggerContext?: LoggingOptions,
335 signal?: AbortSignal,
336 ): Promise<T[]> {
337 await this.ensureConnection();
338 const collection = this.getCollectionName(entityName);
339 /* v8 ignore next */
340 const options: Dictionary = ctx ? { session: ctx } : {};
341 if (signal) {
342 options.signal = signal;
343 }
344 const query = `db.getCollection('${collection}').aggregate(${this.logObject(pipeline)}, ${this.logObject(options)}).toArray();`;
345 const now = Date.now();
346 const res = await this.getCollection(entityName).aggregate<T>(pipeline, options).toArray();
347 this.logQuery(query, { took: Date.now() - now, results: res.length, ...loggerContext });
348
349 return res;
350 }
351
352 async *streamAggregate<T extends object>(
353 entityName: EntityName<T>,

Callers

nothing calls this directly

Calls 5

getCollectionNameMethod · 0.95
logObjectMethod · 0.95
getCollectionMethod · 0.95
logQueryMethod · 0.65
toArrayMethod · 0.45

Tested by

no test coverage detected