Page Contents

Home > @loopback/repository > DefaultCrudRepository > execute

DefaultCrudRepository.execute() method

Execute a MongoDB command.

**WARNING:** In general, it is always better to perform database actions through repository methods. Directly executing MongoDB commands may lead to unexpected results and other issues.


execute(collectionName: string, command: string, ...parameters: PositionalParameters): Promise<AnyObject>;


Parameter Type Description
collectionName string The name of the collection to execute the command on.
command string The command name. See [Collection API docs]( for the list of commands supported by the MongoDB client.
parameters PositionalParameters Command parameters (arguments), as described in MongoDB API docs for individual collection methods.



A promise which resolves to the command output as returned by the database driver.


const result = await repo.execute('MyCollection', 'aggregate', [
  {$lookup: {
    // ...
  {$unwind: '$data'},
  {$out: 'tempData'}