> ## Documentation Index
> Fetch the complete documentation index at: https://www.orionjs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connections

> Configuring MongoDB connections in Orionjs

Orionjs provides a flexible system for configuring and managing MongoDB connections. This allows you to connect to multiple MongoDB instances or databases as needed.

## Default Connection

By default, Orionjs will look for a MongoDB connection string in the `MONGO_URL` or `env.mongo_url` environment variable. This is the simplest way to get started:

```typescript theme={null}
// In your environment configuration
MONGO_URL=mongodb://localhost:27017/my-database
```

You don't need any additional code to use the default connection - all collections will use it automatically unless specified otherwise.

## Connection Initialization

Connections are not started until you call any method in a collection or explicitly call `startConnection` on the collection. This lazy initialization prevents unnecessary connections when a collection is defined but not used.

```typescript theme={null}
// Connection will be initialized when using the collection
const user = await users.findOne({ _id: 'user-123' })

// Or you can explicitly start the connection
await users.startConnection()
```
