CouchbaseQuery
Execute raw N1QL/SQL++ queries with optional parameters.
Syntax
couchbaseQuery(cacheName, query, [parameters])Parameters
cacheName
String
Yes
Name of the cache configuration
query
String
Yes
N1QL/SQL++ query to execute
parameters
Struct
No
Named parameters for the query
Returns
Returns an array of result row structs. Each row contains the selected fields from the query.
Examples
Simple Query
// Basic SELECT query
results = couchbaseQuery(
cacheName = "default",
query = "SELECT * FROM `mybucket` WHERE type = 'user' LIMIT 10"
);
println("Found #results.len()# users");
results.each(function(row) {
println("User: #row.mybucket.name#");
});Parameterized Query
Count Query
Aggregation Query
JOIN Query
Group By Query
Create Index
Update Documents
Delete Documents
Complex Search
Array Contains Query
Subquery
Vector Search Query
Check Index Status
Query Best Practices
Always Use Parameters
Escape Bucket Names
Use Indexes
Notes
N1QL syntax - Uses Couchbase N1QL/SQL++ query language
Backticks required - Always wrap bucket/scope/collection names in backticks
Parameters recommended - Use parameters to prevent injection attacks
Index usage - Create appropriate indexes for query performance
Collection path - Full path:
`bucket`.`scope`.`collection`Case sensitivity - Bucket/scope/collection names are case-sensitive
Error Handling
Related Functions
couchbaseVectorSearch - Simplified vector search
couchbaseVectorList - List vector documents
couchbaseGetCluster - Direct cluster access
See Also
Last updated
Was this helpful?
