@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
54 lines (36 loc) • 1.93 kB
Markdown
---
lang: en
title: 'API docs: repository.defaultcrudrepository.execute_1'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/repository
permalink: /doc/en/lb4/apidocs.repository.defaultcrudrepository.execute_1.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/repository](./repository.md) > [DefaultCrudRepository](./repository.defaultcrudrepository.md) > [execute](./repository.defaultcrudrepository.execute_1.md)
## 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.
<b>Signature:</b>
```typescript
execute(collectionName: string, command: string, ...parameters: PositionalParameters): Promise<AnyObject>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| collectionName | string | The name of the collection to execute the command on. |
| command | string | The command name. See \[Collection API docs\](http://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html) for the list of commands supported by the MongoDB client. |
| parameters | [PositionalParameters](./repository.positionalparameters.md) | Command parameters (arguments), as described in MongoDB API docs for individual collection methods. |
<b>Returns:</b>
Promise<[AnyObject](./repository.anyobject.md)<!-- -->>
A promise which resolves to the command output as returned by the database driver.
## Example
```ts
const result = await repo.execute('MyCollection', 'aggregate', [
{$lookup: {
// ...
}},
{$unwind: '$data'},
{$out: 'tempData'}
]);
```