---
title: "Switch Operations to a Different Database"
url: "https://docs.ravendb.net/6.2/client-api/operations/how-to/switch-operations-to-a-different-database"
version: "6.2"
language: "python"
---

# Switch Operations to a Different Database

> Client language: Python. Also available for [C#](https://docs.ravendb.net/6.2/client-api/operations/how-to/switch-operations-to-a-different-database.md), [Java](https://docs.ravendb.net/6.2/client-api/operations/how-to/switch-operations-to-a-different-database.java.md), [PHP](https://docs.ravendb.net/6.2/client-api/operations/how-to/switch-operations-to-a-different-database.php.md), [Node.js](https://docs.ravendb.net/6.2/client-api/operations/how-to/switch-operations-to-a-different-database.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - By default, all operations work on the default database defined in the [Document Store](https://docs.ravendb.net/6.2/client-api/creating-document-store.md).
>
> - **To operate on a different database**, use the `for_database` method.  
>   If the requested database doesn't exist on the server, an exception will be thrown.
>
> - In this page:
>   - [Common operation: `operations.for_database`](#common-operation:-operationsfor_database)
>   - [Maintenance operation: `maintenance.for_database`](#maintenance-operation:-maintenancefor_database)

## Common operation: `operations.for_database`

- For reference, all common operations are listed [here](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.python.md#common-operations).

```python
# Define default database on the store
document_store = DocumentStore(urls=["yourServerURL"], database="DefaultDB")
document_store.initialize()

with document_store:
  # Use 'for_database', get operation executor for another database
  op_executor = document_store.operations.for_database("AnotherDB")

  # Send the operation, e.g. 'GetRevisionsOperation' will be executed on "AnotherDB"
  revisions_in_another_db = op_executor.send(GetRevisionsOperation("Orders/1-A", Order))

  # Without 'for_database', the operation is executed "DefaultDB"
  revisions_in_default_db = document_store.operations.send(GetRevisionsOperation("Company/1-A", Company))
```

**Syntax**:

```python
def for_database(self, database_name: str) -> OperationExecutor: ...
```

| Parameters | Type | Description |
| - | - | - |
| **database\_name** | `str` | Name of the database to operate on |

| Return Value | Description |
| - | - |
| `OperationExecutor` | New instance of Operation Executor that is scoped to the requested database |

## Maintenance operation: `maintenance.for_database`

- For reference, all maintenance operations are listed [here](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.python.md#maintenance-operations).

```python
# Define default database on the store
document_store = DocumentStore(urls=["yourServerURL"], database="DefaultDB")
document_store.initialize()

with DocumentStore() as document_store:
  # Use 'for_database', get maintenance operation executor for another database
  op_executor = document_store.maintenance.for_database("AnotherDB")
  # Send the maintenance operation, e.g. get database stats for "AnotherDB"
  stats_for_another_db = op_executor.send(GetStatisticsOperation())
  # Without 'for_database', the stats are retrieved for "DefaultDB"
  stats_for_default_db = document_store.maintenance.send(GetStatisticsOperation())
```

**Syntax**:

```python
def for_database(self, database_name: str) -> MaintenanceOperationExecutor: ...
```

| Parameters | Type | Description |
| - | - | - |
| **database\_name** | `str` | Name of the database to operate on |

| Return Value | Description |
| - | - |
| `MaintenanceOperationExecutor` | New instance of Maintenance Operation Executor that is scoped to the requested database |

## See also

- [What are Operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.python.md)
