# MongoDB

> Find, insert, update, and delete documents in your MongoDB collections.

App · Databases · 4 actions. Web page: https://docs.lodol.com/docs/integrations/mongodb

## Actions

### Delete documents

Delete documents from a MongoDB collection.

**Inputs**

- Database (`database`, text, required): The database that contains the collection.
- Collection (`collection`, text, required): Collection containing the documents to delete.
- Filter (`filter`, object, required): A MongoDB query object identifying which documents to delete, e.g. {"_id": "64b0000000000000000000aa"}. Must be non-empty; to delete every document deliberately, use {"_id": {"$exists": true}}.
- Delete all matches (`many`, true/false): Set to true to delete every matching document, or false to delete only the first match. Default: `false`.

**Outputs**

- `deleted_count` (number): Number of deleted documents.

**Example output**

```json
{
  "deleted_count": 1
}
```

### Find documents

Find documents in a MongoDB collection, optionally filtered and limited.

**Inputs**

- Database (`database`, text, required): The database that contains the collection.
- Collection (`collection`, text, required): The collection to read from.
- Filter (`filter`, object): A MongoDB query object of the fields and values documents must match, e.g. {"status": "active"}. Leave blank to return every document. Query operators such as $gt, $in and $regex are supported.
- Limit (`limit`, number): The maximum number of documents to return. At least 1.

**Outputs**

- `count` (number): Number of documents returned.
- `documents` (list): The matching documents. Each document's _id is returned as a string.

**Example output**

```json
{
  "count": 1,
  "documents": [
    {
      "_id": "64b0000000000000000000aa",
      "active": true,
      "name": "Ada"
    }
  ]
}
```

### Insert documents

Insert one or more documents into a MongoDB collection.

**Inputs**

- Database (`database`, text, required): The database that contains the collection.
- Collection (`collection`, text, required): The collection to insert into. Pick an existing collection, or reference a name from an earlier step to create one on the fly (MongoDB creates the collection automatically on first insert).
- Documents (`documents`, list, required): The documents to insert. Each item is an object of field names and values. Omit _id to let MongoDB generate one.

**Outputs**

- `inserted_count` (number): Number of documents inserted.
- `inserted_ids` (list): The _id of each inserted document, as strings.

**Example output**

```json
{
  "inserted_count": 1,
  "inserted_ids": [
    "64b0000000000000000000bb"
  ]
}
```

### Update documents

Update documents in a MongoDB collection.

**Inputs**

- Database (`database`, text, required): The database that contains the collection.
- Collection (`collection`, text, required): Collection containing the documents to update.
- Filter (`filter`, object, required): A MongoDB query object identifying which documents to update, e.g. {"email": "ada@example.com"}. Must be non-empty; to update every document deliberately, use {"_id": {"$exists": true}}.
- Updates (`updates`, object, required): The fields and new values to save on each matching document (applied with MongoDB's $set), e.g. {"status": "archived"}.
- Update all matches (`many`, true/false): Set to true to update every matching document, or false to update only the first match. Default: `false`.

**Outputs**

- `matched_count` (number): Number of matched documents.
- `modified_count` (number): Number of modified documents.

**Example output**

```json
{
  "matched_count": 1,
  "modified_count": 1
}
```
