> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetbucket.md).

# CouchbaseGetBucket

Get a Couchbase bucket instance for bucket-level operations.

## Syntax

```js
couchbaseGetBucket(cacheName)
```

## Parameters

| Parameter   | Type   | Required | Description                     |
| ----------- | ------ | -------- | ------------------------------- |
| `cacheName` | String | Yes      | Name of the cache configuration |

## Returns

Returns the Couchbase `Bucket` instance with access to:

* Scope management
* Collection access
* Bucket statistics
* Ping operations
* View queries (legacy)

## Examples

### Basic Usage

```js
// Get bucket instance
bucket = couchbaseGetBucket("default");

// Get bucket name
println("Bucket name: #bucket.name()#");
```

### Access Collections

```js
bucket = couchbaseGetBucket("default");

// Get default scope and collection
scope = bucket.defaultScope();
collection = scope.defaultCollection();

// Or get specific scope/collection
customScope = bucket.scope("myapp");
customCollection = customScope.collection("users");
```

### Bucket Operations

```js
bucket = couchbaseGetBucket("default");

// Ping bucket health
pingResult = bucket.ping();
println("Bucket status: #pingResult.version()#");

// Get collections
allScopes = bucket.collections();
```

### Multiple Buckets

```js
// Different buckets for different data
usersBucket = couchbaseGetBucket("users-cache");
sessionsBucket = couchbaseGetBucket("sessions-cache");
vectorsBucket = couchbaseGetBucket("vectors-cache");

// Access their collections independently
usersCollection = usersBucket.defaultScope().defaultCollection();
sessionsCollection = sessionsBucket.defaultScope().defaultCollection();
vectorsCollection = vectorsBucket.defaultScope().defaultCollection();
```

### Bucket Statistics

```js
bucket = couchbaseGetBucket("default");

// Get bucket info (requires cluster admin)
cluster = couchbaseGetCluster("default");
bucketManager = cluster.buckets();
bucketSettings = bucketManager.getBucket(bucket.name());

println("RAM quota: #bucketSettings.ramQuota()# MB");
println("Replica count: #bucketSettings.numReplicas()#");
```

## Notes

* Bucket name is determined by cache configuration
* Bucket instance is cached and reused
* Use `couchbaseGetCollection()` for direct collection access
* Most operations should use collection-level access
* Bucket-level access is useful for management and statistics

## Related Functions

* [couchbaseGetCluster](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetcluster.md) - Get cluster connection
* [couchbaseGetScope](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetscope.md) - Get scope instance
* [couchbaseGetCollection](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetcollection.md) - Get collection instance

## See Also

* [API Usage Guide](/boxlang-+-++/modules/bx-couchbase/api-usage.md)
* [Couchbase Bucket API](https://docs.couchbase.com/java-sdk/current/howtos/managing-connections.html)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetbucket.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
