---
title: Migration in MongoDB (Deprecated)
description: "This is a step-by-step guide for upgrading to the latest version of Agenta"
---

:::caution
  This guide is depracated as it relates to the migration for agenta versions up
  to v0.18 which have used MongoDB as a database. Starting with v0.19 we now use
  Postgres as a database. If you are using an old version of agenta, use this
  guide to migrate all your data to v0.18 then follow the guide for migrating to
  postgres [here](/self-host/migration/migration-to-postgres).{" "}
:::


## Upgrading to the Latest Version

To upgrade to the latest version of Agenta, execute the following command:

```
docker compose -f docker-compose.gh.yml up -d --pull always
```

This command instructs Docker to fetch and use the latest version of the Agenta image.

# Database Migrations

The steps below outlines the process for performing database migrations using Beanie with the Agenta backend system.

Beanie is a MongoDB ODM (Object Document Mapper) for Python. More information about Beanie can be found [here](https://github.com/roman-right/beanie).

## Steps for Migration

### Accessing the Backend Docker Container

To access the backend Docker container:

1. **List Docker Containers**: List all running Docker containers with the command:

   ```bash
   docker ps
   ```

2. **Identify the `agenta-backend` Container ID**: Note down the container ID from the output. Example output:

   ```
   CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS                                      NAMES
   ae0c56933636   agenta-backend           "uvicorn agenta_back…"   3 hours ago     Up 3 hours     8000/tcp                                   agenta-backend-1
   e35f6c8b7fcb   agenta-agenta-web        "docker-entrypoint.s…"   3 hours ago     Up 3 hours     0.0.0.0:3000->3000/tcp                     agenta-agenta-web-1
   ```

3. **SSH into the Container**: Use the following command, replacing `CONTAINER_ID` with your container's ID:

   ```bash
   docker exec -it CONTAINER_ID bash
   ```

### Performing the Migration

To perform the database migration:

1. **Navigate to the Migration Directory**: Change the directory to the migration folder:

   ```sh
   cd agenta_backend/migrations/{migration_name}
   ```

   Replace `{migration_name}` with the actual migration name, e.g., `v0_10_0_to_v0_11_0`.

2. **Run Beanie Migration**: Execute the migration command:

   ```sh
   beanie migrate --no-use-transaction -uri 'mongodb://username:password@mongo' -db 'agenta_v2' -p .
   ```

   Ensure to replace `username`, `password`, and other placeholders with actual values.
