First 50 of 200 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.
Continue in the practice tool above to load more questions, 50 at a time.
Question 1Couchbase Data Modeling and Querying
In Couchbase, which statement accurately describes the relationship between documents, collections, and scopes?
- A bucket groups documents and resides inside a collection, which itself resides inside a scope.
- A scope groups documents and resides inside a collection, which itself resides inside a bucket.
- A collection groups documents and resides inside a scope, which itself resides inside a bucket. Correct answer.
- A document groups collections and resides inside a scope, which itself resides inside a bucket.
Explanation
Couchbase's hierarchy is bucket, then scope, then collection, then documents. A scope is a namespace for related collections, and each collection holds the JSON documents themselves.
Question 2Couchbase Data Modeling and Querying
A developer needs a unique identifier generated automatically for a new JSON document. Which document key behavior applies when the key is not supplied explicitly?
- Couchbase rejects the write because document keys are mandatory.
- Couchbase generates a UUID for the document key. Correct answer.
- Couchbase requires the document to include an 'id' field that becomes the key.
- Couchbase derives the key from the first field in the JSON body.
Explanation
If no key is provided on insert, the SDK/server generates a random UUID as the document key. The key is metadata separate from the document body, so no field inside the JSON becomes the key automatically.
Question 3Couchbase Data Modeling and Querying
Which N1QL query returns only the 'name' and 'email' fields of every document in the 'users' collection?
- SELECT FIELDS name, email FROM users
- SELECT name, email FROM users Correct answer.
- SELECT users.name, users.email FROM users
- SELECT * FROM users WHERE name, email
Explanation
In N1QL the SELECT clause lists the projected fields by name, and FROM names the keyspace. Listing name and email projects just those two fields from each document.
Question 4Couchbase Data Modeling and Querying
What does the N1QL WHERE clause do in a SELECT statement?
- It sorts the result set by the listed expressions.
- It limits how many documents the query returns.
- It groups documents that share a common value.
- It filters documents, keeping only those for which the predicate evaluates to TRUE. Correct answer.
Explanation
WHERE applies a boolean predicate to each candidate document, and only those evaluating to TRUE proceed to projection. Sorting, grouping, and limiting are handled by ORDER BY, GROUP BY, and LIMIT respectively.
Question 5Couchbase Data Modeling and Querying
Which statement about a primary index in Couchbase Query is accurate?
- It enables full scans and is required before a keyspace can be queried without a secondary index. Correct answer.
- It enforces uniqueness on the document key field.
- It stores a copy of the entire document body for fast retrieval.
- It can only be created on a single-field expression.
Explanation
A primary index indexes document keys and allows the query service to scan a keyspace when no more specific index applies. Without any index, queries against that keyspace fail.
Question 6Couchbase Data Modeling and Querying
A document stores tags as a JSON array. Which N1QL predicate tests whether the array contains the value "sale"?
- WHERE tags = "sale"
- WHERE tags LIKE "sale"
- WHERE "sale" IN tags Correct answer.
- WHERE CONTAINS(tags, "sale")
Explanation
The IN operator checks membership, so "sale" IN tags is TRUE when the array includes that element. Equality compares the whole array, and LIKE performs string pattern matching rather than array membership.
Question 7Couchbase Data Modeling and Querying
Which N1QL clause is used to sort query results by a field in descending order?
- GROUP BY field DESC
- ORDER field DESC
- SORT BY field DESC
- ORDER BY field DESC Correct answer.
Explanation
ORDER BY sorts the result set, and the DESC modifier reverses the default ascending order. GROUP BY aggregates rows rather than ordering output.
Question 8Couchbase Data Modeling and Querying
Which Couchbase SDK operation retrieves a document by its key with the lowest overhead?
- A key-value get on the bucket Correct answer.
- A full-text search request matching the key
- A view query that emits the key
- An N1QL query filtered on the key
Explanation
A key-value get resolves the document directly by key through the data service, avoiding query parsing and index lookup. N1QL, full-text search, and views add layers that increase latency.
Question 9Couchbase Data Modeling and Querying
A query filters on a field inside a nested object, and the developer wants an index to support it. Which index definition is appropriate?
- CREATE INDEX idx ON bucket(scope.collection.nestedField) AS nestedField
- CREATE INDEX idx ON bucket(scope.collection.nestedField) Correct answer.
- CREATE INDEX idx ON bucket(scope.collection) WHERE nestedField
- CREATE INDEX idx ON bucket(scope.collection) USING nestedField
Explanation
Index keys can reference nested paths using dot notation, so the path to the nested field is placed inside the index key expression. The keyspace is named first, then the dotted field path.
Question 10Couchbase Data Modeling and Querying
Which N1QL construct computes a per-category count of documents and requires that every non-aggregated projected field appear in the grouping clause?
- GROUP BY with an aggregate such as COUNT(*) Correct answer.
- LET with an aggregate such as COUNT(*)
- ORDER BY with an aggregate such as COUNT(*)
- UNNEST with an aggregate such as COUNT(*)
Explanation
GROUP BY forms groups of rows sharing the grouping expressions, and aggregates like COUNT(*) are computed per group. Any non-aggregated field in the projection must be part of the GROUP BY list.
Question 11Couchbase Data Modeling and Querying
A developer needs to turn each element of an array field into separate result rows for filtering. Which N1QL clause accomplishes this?
- UNNEST Correct answer.
- JOIN ARRAY
- EXPLODE
- FLATTEN
Explanation
UNNEST takes an array expression and produces one output row per element, which can then be filtered or projected. It is the standard N1QL mechanism for array flattening in queries.
Question 12Couchbase Data Modeling and Querying
Which statement about the USE KEYS clause in N1QL is correct?
- It restricts the query to specific document keys and can avoid a full index scan. Correct answer.
- It renames the document key in the output projection.
- It joins two keyspaces on their document keys.
- It creates a new document key for each result row.
Explanation
USE KEYS supplies an explicit list or expression of document keys, so the query fetches only those documents directly. This bypasses the need to scan a broader index for matching keys.
Question 13Couchbase Data Modeling and Querying
What is the main purpose of a covering index in Couchbase Query?
- To replicate documents across data centers.
- To compress the document body on disk.
- To enforce referential integrity between collections.
- To answer a query entirely from index data without fetching the full document. Correct answer.
Explanation
A covering index includes all fields the query needs, so the query service can satisfy the request from the index alone. This avoids a fetch from the data service for each result document.
Question 14Couchbase Data Modeling and Querying
A developer queries a field that may be absent in some documents and wants missing values treated as null rather than causing an error. Which approach is most appropriate?
- Use ORDER BY on the field to coerce missing values.
- Use IFMISSINGORNULL or a similar function to substitute a default value. Correct answer.
- Use a WHERE clause that requires the field to exist.
- Use a primary index so missing fields are ignored.
Explanation
IFMISSINGORNULL returns a fallback value when the expression is MISSING or NULL, keeping the projection well-defined. Filtering out documents with the field would discard rows rather than supply a default.
Question 15Couchbase Data Modeling and Querying
Which N1QL expression extracts the value at key "city" from an object stored in the field 'address'?
- address->city
- CITY(address)
- address[city]
- address.city Correct answer.
Explanation
Dot notation navigates into a nested object, so address.city yields the value stored under the city key. Bracket notation with a bare identifier is not valid for object field access.
Question 16Couchbase Data Modeling and Querying
A developer wants to return only the first 10 results after sorting. Which clause combination achieves this correctly?
- GROUP BY score DESC LIMIT 10
- ORDER BY score DESC OFFSET 10
- LIMIT 10 ORDER BY score DESC
- ORDER BY score DESC LIMIT 10 Correct answer.
Explanation
ORDER BY sorts the full result set, and LIMIT then truncates it to the requested count. Placing LIMIT before ORDER BY is invalid because clause order matters in N1QL.
Question 17Couchbase Data Modeling and Querying
Which statement best explains why denormalizing related data into a single document can be beneficial in Couchbase?
- It allows related data to be read atomically with a single key-value fetch. Correct answer.
- It automatically enforces uniqueness across collections.
- It guarantees that documents never exceed the size limit.
- It removes the need for any indexes on the bucket.
Explanation
Embedding related data lets the application retrieve a consistent aggregate with one key lookup, which is efficient on a distributed store. It does not remove indexing needs or enforce uniqueness.
Question 18Couchbase Data Modeling and Querying
A document uses a type discriminator field, and queries always filter on that type plus a status. Which index design supports these queries best?
- A composite index on the type and status fields Correct answer.
- A primary index only
- A single-field index on status only
- A full-text index on the type field
Explanation
A composite index whose leading key matches the common predicate lets the query service seek directly to matching entries. Including both type and status aligns the index with the filter pattern.
Question 19Couchbase Data Modeling and Querying
Which N1QL statement correctly inserts a new document with an explicit key into a collection?
- INSERT INTO users (KEY, VALUE) VALUES ("user::1", {"name":"Ana"}) Correct answer.
- CREATE DOCUMENT users KEY "user::1" {"name":"Ana"}
- INSERT INTO users VALUES ("user::1", {"name":"Ana"})
- UPSERT users KEY "user::1" VALUE {"name":"Ana"}
Explanation
The INSERT INTO ... (KEY, VALUE) VALUES form supplies both the document key and the JSON body explicitly. This is the standard DML syntax for inserting with a chosen key.
Question 20Couchbase Data Modeling and Querying
A developer needs to update a single nested field inside an existing document without replacing the whole body. Which approach is correct?
- Use a key-value replace with the unchanged body.
- Use DELETE followed by INSERT of the modified body.
- Use UPDATE with a SET clause targeting the nested path. Correct answer.
- Use INSERT to overwrite the document with a new body.
Explanation
UPDATE with SET modifies the specified path in place, preserving other fields in the document. Replacing or deleting and reinserting discards or rewrites unrelated data.
Question 21Couchbase Data Modeling and Querying
Which statement about N1QL JOIN between two collections in the same scope is accurate?
- JOIN requires both collections to share identical document keys.
- JOIN can only combine a collection with an array field.
- JOIN matches documents from both keyspaces on a join predicate and can use indexes on the join keys. Correct answer.
- JOIN always performs a full scan and cannot use indexes.
Explanation
N1QL JOIN combines documents from two keyspaces when the ON predicate holds, and indexes on the join keys can speed the lookup. Keys do not need to be identical between the collections.
Question 22Couchbase Data Modeling and Querying
A query filters on LOWER(email) and is slow. Which change most directly enables an index to serve the predicate?
- Create an index on email with a WHERE clause on LOWER(email).
- Create an index on email and keep filtering with LOWER(email).
- Create a primary index and remove the LOWER function.
- Create an index on the expression LOWER(email) and query using the same expression. Correct answer.
Explanation
An index must match the expression used in the predicate, so indexing LOWER(email) lets the query seek on that computed value. An index on the raw email column does not match a function-wrapped predicate.
Question 23Couchbase Data Modeling and Querying
A developer must model a many-to-many relationship between users and groups on a distributed document store. Which modeling choice is most appropriate?
- Embed all users inside every group document as a nested array.
- Store group references in each user document and user references in each group document, accepting controlled duplication. Correct answer.
- Store both entities in one document per user and never reference groups.
- Create a separate collection for each user-group pair dynamically.
Explanation
Bidirectional references with controlled duplication let each side be read with a single lookup while keeping documents bounded. Embedding every user in every group risks unbounded document growth.
Question 24Couchbase Data Modeling and Querying
Which statement correctly describes the consistency behavior of a N1QL query immediately after a key-value write to the same document?
- The query may not see the write until the index is updated, unless scan consistency is set to request plus. Correct answer.
- The query never sees the write because indexes are read-only.
- The query always sees the write instantly because indexes are updated synchronously.
- The query sees the write only if a primary index exists.
Explanation
Secondary indexes are updated asynchronously, so a query can lag behind recent writes. Request-plus scan consistency makes the query wait until the index has caught up to a specified mutation token.
Question 25Couchbase Data Modeling and Querying
A developer wants to paginate results deterministically across pages while new documents are being inserted. Which approach avoids skipped or duplicated rows?
- Order by a non-unique field and paginate with OFFSET.
- Paginate by random sampling of the result set.
- Paginate with LIMIT only, without ordering.
- Order by a unique key and paginate using a keyset cursor on that key. Correct answer.
Explanation
Keyset pagination orders by a unique key and resumes after the last seen value, so concurrent inserts do not shift page boundaries. OFFSET pagination over a non-unique sort can skip or repeat rows as data changes.
Question 26Couchbase Data Modeling and Querying
In Couchbase's data hierarchy, which level sits immediately below a bucket and groups related collections?
- Partition
- Scope Correct answer.
- Namespace
- Keyspace
Explanation
A bucket contains one or more scopes, and each scope contains collections that hold documents. This scope level was introduced with the collections feature to let multiple applications share a bucket while keeping their data separated logically.
Question 27Couchbase Data Modeling and Querying
A document key must be unique within which boundary?
- The bucket
- The cluster
- The scope
- The collection Correct answer.
Explanation
Document keys are unique inside a collection. Two different collections, even in the same scope, may each hold a document with the same key without conflict. This matters when designing keyspaces for separate applications sharing a bucket.
Question 28Couchbase Data Modeling and Querying
Which N1QL function returns the number of elements in an array field named 'items'?
- LEN(items)
- SIZE(items) Correct answer.
- COUNT(items)
- ARRAY_LENGTH(items)
Explanation
SIZE() returns the number of elements in an array or the length of a string. It is a scalar function evaluated per document, so it can appear in projections and WHERE clauses.
Question 29Couchbase Data Modeling and Querying
A developer wants to add a new field to an existing document while leaving all other fields untouched. Which N1QL statement achieves this?
- INSERT INTO bucket (KEY, VALUE) VALUES ('doc1', {'newField': 1})
- MERGE INTO bucket USING ...
- UPDATE bucket SET newField = 1 WHERE META().id = 'doc1' Correct answer.
- UPSERT INTO bucket (KEY, VALUE) VALUES ('doc1', {'newField': 1})
Explanation
The UPDATE statement with SET modifies only the specified field of a matching document, preserving the rest of the body. An upsert or insert with a full value object would replace the document contents.
Question 30Couchbase Data Modeling and Querying
Which index type in Couchbase Query is the primary choice for supporting equality, range, and ORDER BY predicates on scalar fields?
- Memory-optimized index
- Full-text search index
- Global secondary index Correct answer.
- Hash index
Explanation
Global secondary indexes (GSI) are the standard secondary index mechanism for N1QL and support equality, range, and ordering predicates. They are maintained asynchronously and served by the index service.
Question 31Couchbase Data Modeling and Querying
What does the META().id expression return in a N1QL query?
- The document's revision number
- The document's key Correct answer.
- The document's expiration time
- The document's CAS value
Explanation
META().id exposes the document key as a field that can be projected or filtered. It is commonly used to return keys or to filter by key pattern. Other metadata such as CAS and expiration are accessed through different META() fields.
Question 32Couchbase Data Modeling and Querying
Which N1QL clause removes duplicate rows from a result set?
- GROUP BY
- FILTER
- DISTINCT Correct answer.
- UNIQUE
Explanation
The DISTINCT keyword in the SELECT clause eliminates duplicate result rows. GROUP BY groups rows for aggregation but does not by itself deduplicate arbitrary projected values unless every projected field is grouped.
Question 33Couchbase Data Modeling and Querying
A developer needs to store a document with a server-generated key rather than supplying one. Which approach accomplishes this?
- Use UPSERT with an empty string key
- Use INSERT with a KEY clause set to NULL
- Use UPDATE with no WHERE clause
- Use the SDK insert without a key, which generates a UUID Correct answer.
Explanation
When no key is supplied, the SDK generates a unique key, typically a UUID, for the new document. This is useful when the application does not have a natural key and wants the server or client library to assign one.
Question 34Couchbase Data Modeling and Querying
A developer wants to project only the fields 'name' and 'email' from each document. Which SELECT form is most appropriate?
- SELECT * FROM users
- SELECT name, email FROM users Correct answer.
- SELECT VALUE name, email FROM users
- SELECT RAW name, email FROM users
Explanation
Listing the desired fields in the SELECT clause produces an object per row containing only those fields. SELECT * returns the entire document body, which is wasteful when only a few fields are needed.
Question 35Couchbase Data Modeling and Querying
A developer needs to filter documents where the numeric field 'score' is between 10 and 20 inclusive. Which predicate is correct?
- WHERE score BETWEEN 10 AND 20 Correct answer.
- WHERE score = 10 OR score = 20
- WHERE score > 10 AND score < 20
- WHERE score IN [10, 20]
Explanation
BETWEEN is inclusive on both bounds, so it matches values from 10 through 20. Using strict inequality would exclude the endpoints, which changes the intended result.
Question 36Couchbase Data Modeling and Querying
A query uses ORDER BY on field 'createdAt' and also filters on 'status'. Which index definition best supports both operations?
- CREATE INDEX idx ON bucket(createdAt)
- CREATE INDEX idx ON bucket(status, createdAt) Correct answer.
- CREATE INDEX idx ON bucket(status)
- CREATE INDEX idx ON bucket(createdAt, status)
Explanation
Putting the equality predicate field first and the ordering field second lets the index serve the filter and provide sorted output. Index key order matters because the leading field is used for the equality match.
Question 37Couchbase Data Modeling and Querying
Which N1QL clause is used with an aggregate to compute subtotals per group?
- LET
- GROUP BY Correct answer.
- ORDER BY
- HAVING
Explanation
GROUP BY partitions rows into groups so aggregate functions produce one value per group. HAVING then filters those groups after aggregation.
Question 38Couchbase Data Modeling and Querying
A developer needs to merge an array of new tag values into an existing array field without duplicates. Which N1QL function is most appropriate?
- ARRAY_PREPEND
- ARRAY_APPEND
- ARRAY_DISTINCT Correct answer.
- ARRAY_CONCAT
Explanation
ARRAY_DISTINCT returns the distinct values of an array, which is useful to remove duplicates after combining arrays. A common pattern concatenates then applies ARRAY_DISTINCT.
Question 39Couchbase Data Modeling and Querying
Which N1QL expression returns the value of field 'total' or the string 'n/a' when the field is missing?
- IFMISSINGORNULL(total, 'n/a') Correct answer.
- NVL(total, 'n/a')
- IFNULL(total, 'n/a')
- COALESCE(total, 'n/a')
Explanation
IFMISSINGORNULL returns the fallback when the expression evaluates to MISSING or NULL. This is important because a missing field and a null value are distinct in N1QL.
Question 40Couchbase Data Modeling and Querying
A developer wants to count documents per status but only include groups with more than five documents. Which clause filters on the aggregate?
- WHERE COUNT(*) > 5
- LIMIT COUNT(*) > 5
- HAVING COUNT(*) > 5 Correct answer.
- GROUP BY COUNT(*) > 5
Explanation
HAVING is evaluated after grouping and can reference aggregate expressions. A WHERE clause is evaluated before grouping and cannot filter on an aggregate result.
Question 41Couchbase Data Modeling and Querying
Which statement about the N1QL 'USE KEYS' clause is accurate when the keys are supplied as a literal array?
- It fetches documents directly by key without requiring a secondary index Correct answer.
- It requires a primary index to be defined
- It performs a full scan and filters after fetching
- It can only be used in UPDATE statements
Explanation
USE KEYS resolves documents by their keys and does not need a secondary index. This makes it an efficient way to fetch a known set of documents.
Question 42Couchbase Data Modeling and Querying
A developer wants to build a query that returns each document's key alongside a field, and the key must be available for filtering. Which approach is valid?
- Use a special $key variable
- Use a WHERE clause on META().id without projection
- Project META().id AS docKey in the SELECT list Correct answer.
- Reference the key through the document body
Explanation
META().id can be projected with an alias so the key appears in the result. It can also be used in WHERE clauses. There is no $key variable automatically injected into the document body.
Question 43Couchbase Data Modeling and Querying
A developer needs to update a numeric counter atomically across concurrent writers. Which N1QL approach is appropriate?
- Read the value, add one in the application, then write it back
- Use UPDATE with SET counter = counter + 1 Correct answer.
- Use a transaction-free MERGE
- Use an UPSERT with a computed value
Explanation
An UPDATE that references the existing field in the SET expression performs the increment server-side. This avoids the lost-update race that occurs with read-modify-write in the application.
Question 44Couchbase Data Modeling and Querying
Which N1QL feature allows a query to reference a subquery that returns an array for use in the outer query?
- A correlated subquery in the SELECT or WHERE clause Correct answer.
- A LET variable bound to a scalar
- A HAVING clause
- A USE KEYS clause
Explanation
N1QL supports subqueries, including correlated subqueries that reference the outer document. The subquery result can be used as an array or scalar in the outer query.
Question 45Couchbase Data Modeling and Querying
A developer wants to return a document field as a top-level array rather than wrapped in an object per row. Which SELECT form should be used?
- SELECT field FROM bucket
- SELECT OBJECT field FROM bucket
- SELECT VALUE field FROM bucket
- SELECT RAW field FROM bucket Correct answer.
Explanation
SELECT RAW returns each expression value directly without the object wrapper. This is useful when the client expects a plain array of values.
Question 46Couchbase Data Modeling and Querying
A developer needs to query documents where a nested object field 'address.zip' equals a value, and the index must support this efficiently. Which index definition is appropriate?
- CREATE INDEX idx ON bucket(address)
- CREATE INDEX idx ON bucket(address.zip, META().id)
- CREATE INDEX idx ON bucket(address.zip) Correct answer.
- CREATE INDEX idx ON bucket(META().id)
Explanation
An index on the dotted path address.zip targets the nested field directly. Indexing the whole address object would not efficiently match a predicate on a single nested field.
Question 47Couchbase Data Modeling and Querying
A developer must ensure a query uses a specific index rather than letting the optimizer choose. Which N1QL hint accomplishes this?
- INDEX HINT
- FORCE INDEX
- WITH INDEX
- USE INDEX Correct answer.
Explanation
The USE INDEX hint in the FROM clause tells the optimizer to consider the named index. It is useful when the optimizer chooses a suboptimal index.
Question 48Couchbase Data Modeling and Querying
A developer observes that a query using a function on an indexed field does not use the index. Which change most directly restores index usage?
- Rewrite the predicate to compare the bare field against a precomputed value Correct answer.
- Increase the query timeout
- Add a covering index on the function result
- Add a USE KEYS clause
Explanation
Applying a function to an indexed field prevents the optimizer from using a plain index on that field. Rewriting to compare the bare field, or creating an index on the function expression, restores index usage.
Question 49Couchbase Data Modeling and Querying
A developer needs to model a one-to-many relationship where the many side can grow without bound. Which modeling choice is generally preferred in Couchbase?
- Store the parent in a child document
- Embed all children in the parent document
- Use a join table
- Store children as separate documents with a reference to the parent Correct answer.
Explanation
Unbounded arrays embedded in a parent document can grow large and cause write amplification. Storing children as separate documents with a parent reference keeps document sizes bounded and allows independent updates.
Question 50Couchbase Data Modeling and Querying
A developer needs to return the top three documents by score within each category. Which N1QL approach is most appropriate?
- Use GROUP BY category with MAX(score)
- Use DISTINCT on category and score
- Use a window function such as RANK() over a partition Correct answer.
- Use ORDER BY score DESC LIMIT 3
Explanation
Window functions can rank rows within a partition defined by category, allowing the query to filter to the top rows per group. A simple LIMIT applies to the whole result set, not per category.