> 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/couchbasegetscope.md).

# CouchbaseGetScope

Get a Couchbase scope instance within a bucket.

## Syntax

```js
couchbaseGetScope(cacheName, [scopeName])
```

## Parameters

| Parameter   | Type   | Required | Default    | Description                         |
| ----------- | ------ | -------- | ---------- | ----------------------------------- |
| `cacheName` | String | Yes      | -          | Name of the cache configuration     |
| `scopeName` | String | No       | `_default` | Name of the scope within the bucket |

## Returns

Returns the Couchbase `Scope` instance with access to:

* Collection management
* Query execution scoped to this scope
* Analytics scoped to this scope

## Examples

### Get Default Scope

```js
// Get default scope (most common)
scope = couchbaseGetScope("default");

// Access default collection
collection = scope.defaultCollection();
```

### Get Custom Scope

```js
// Get specific scope
myAppScope = couchbaseGetScope("default", "myapp");

// Access collections in this scope
usersCollection = myAppScope.collection("users");
ordersCollection = myAppScope.collection("orders");
```

### Execute Scoped Queries

```js
scope = couchbaseGetScope("default", "myapp");

// Query within this scope
result = scope.query(
    "SELECT * FROM users WHERE status = 'active'"
);
```

### Multiple Scopes

```js
// Different scopes for different app modules
authScope = couchbaseGetScope("default", "auth");
ecomScope = couchbaseGetScope("default", "ecommerce");
analyticsScope = couchbaseGetScope("default", "analytics");

// Each scope has its own collections
usersCollection = authScope.collection("users");
productsCollection = ecomScope.collection("products");
eventsCollection = analyticsScope.collection("events");
```

### Scope Organization

```js
// Organize by environment
devScope = couchbaseGetScope("app-cache", "development");
prodScope = couchbaseGetScope("app-cache", "production");

// Same collection names, different scopes
devUsersCollection = devScope.collection("users");
prodUsersCollection = prodScope.collection("users");
```

## Notes

* Default scope is `_default` (Couchbase standard)
* Scopes provide namespace isolation within a bucket
* Useful for multi-tenant applications
* Each scope can have multiple collections
* Scope names are case-sensitive
* Scope must exist in Couchbase or operation will fail

## Scope Benefits

* **Namespace isolation** - Separate data logically within one bucket
* **Access control** - Grant permissions per scope
* **Organization** - Group related collections together
* **Multi-tenancy** - Isolate tenant data within scopes
* **Environment separation** - dev/staging/prod in same bucket

## Related Functions

* [couchbaseGetBucket](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetbucket.md) - Get bucket instance
* [couchbaseGetCollection](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetcollection.md) - Get collection instance
* [couchbaseQuery](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasequery.md) - Execute queries

## See Also

* [API Usage Guide](/boxlang-+-++/modules/bx-couchbase/api-usage.md)
* [Couchbase Scopes & Collections](https://docs.couchbase.com/server/current/learn/data/scopes-and-collections.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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
