Azure Cosmos DB is a globally distributed, multi-model database service designed for modern app development. This guide offers 30 carefully selected Azure Cosmos DB MCQ questions and answers covering SQL API querying, SDK usage, CRUD operations, triggers, UDFs, and query optimization. Perfect for developers, these questions will enhance your understanding of efficient Cosmos DB usage.
MCQs
1. Writing Queries with SQL API
Which SQL API keyword is used to query data from a container in Azure Cosmos DB? a) SELECT b) GET c) FETCH d) QUERY
What is the purpose of the “OFFSET LIMIT” clause in Cosmos DB SQL API? a) Sorting results b) Pagination of query results c) Joining two containers d) Filtering specific fields
Which type of clause does Cosmos DB SQL API use to filter query results? a) GROUP BY b) WHERE c) HAVING d) FILTER
In Cosmos DB SQL API, which function calculates the total number of items in a container? a) COUNT() b) SUM() c) TOTAL() d) AGGREGATE()
What is returned by the SELECT statement in Azure Cosmos DB SQL API? a) Rows b) JSON documents c) Scalar values d) Arrays
How can you retrieve a specific property from a JSON document in Cosmos DB SQL API? a) Using the EXTRACT function b) Referencing the property by name c) Using a JOIN clause d) By calling a UDF
2. Working with SDKs: .NET, Java, Python, Node.js
Which of the following is a supported SDK for Azure Cosmos DB? a) PHP SDK b) .NET SDK c) Ruby SDK d) Swift SDK
In the .NET SDK, what method is used to create a new container in Cosmos DB? a) CreateDatabaseAsync() b) CreateContainerAsync() c) AddContainerAsync() d) InitializeContainerAsync()
Which Java SDK class is used to perform queries in Azure Cosmos DB? a) CosmosQueryClient b) CosmosDatabaseQuery c) CosmosAsyncContainer d) CosmosTableQuery
In Python SDK, how do you connect to an Azure Cosmos DB account? a) Using the connect_to_cosmos() function b) By initializing a CosmosClient object c) With the cosmos.connect() method d) Through REST APIs
Which Node.js package is used for Azure Cosmos DB integration? a) @azure/cosmos b) azure-sdk-db c) cosmos-db-client d) cosmos-sdk-node
How do you execute a stored procedure using the .NET SDK? a) ExecuteStoredProcedureAsync() b) RunStoredProcedure() c) CallProcedure() d) ExecuteProcedureAsync()
3. CRUD Operations and Stored Procedures
What is the method to create a document in Cosmos DB using SQL API? a) INSERT INTO b) ADD ITEM c) CREATE DOCUMENT d) POST ITEM
Which SDK operation is used to update a document in Azure Cosmos DB? a) ReplaceItemAsync() b) ModifyDocument() c) UpdateRecord() d) PatchItemAsync()
How does Azure Cosmos DB ensure uniqueness of a document? a) By using the partition key and id property b) By automatically indexing all properties c) Through primary key constraints d) Using stored procedures
Which operation is required to delete a container in Cosmos DB? a) DeleteContainerAsync() b) DropTable() c) RemoveCollection() d) DestroyContainer()
In Cosmos DB, stored procedures are written in: a) SQL b) JavaScript c) Python d) Java
What is the benefit of using stored procedures in Cosmos DB? a) Distributed transaction management b) Index management c) Performing operations within a single partition d) Increasing partition count
4. Using Triggers and User-Defined Functions (UDFs)
Triggers in Azure Cosmos DB are executed: a) Before or after an operation b) Only before an operation c) Only after an operation d) Independently of operations
What is the purpose of UDFs in Cosmos DB? a) To define schema constraints b) To apply custom logic during queries c) To manage containers d) To control access permissions
UDFs in Cosmos DB are written in: a) SQL b) JavaScript c) Python d) C#
How are triggers associated with operations in Cosmos DB? a) By specifying the trigger name during the operation b) Through host.json configurations c) Using a trigger binding in SDKs d) Triggers are automatically applied
Which SDK method is used to create a trigger in Cosmos DB? a) CreateTriggerAsync() b) DefineTrigger() c) AddTrigger() d) InitializeTriggerAsync()
When should you use a post-trigger in Cosmos DB? a) To validate data before insertion b) To log changes after an operation c) To aggregate data across partitions d) To modify indexing policies
5. Optimizing Query Performance
How can you improve query performance in Azure Cosmos DB? a) By using proper indexing b) By reducing partition count c) Using a relational schema d) Avoiding JSON format
What is the purpose of the partition key in Cosmos DB? a) To manage indexing b) To distribute data across partitions c) To secure the database d) To perform bulk operations
Which indexing mode is default in Azure Cosmos DB? a) Manual b) Automatic c) Lazy d) No Index
What tool helps monitor query performance in Cosmos DB? a) Azure Monitor b) Query Metrics in Azure Portal c) Azure Storage Explorer d) Log Analytics
Which consistency level offers the lowest latency in Cosmos DB? a) Eventual b) Strong c) Bounded Staleness d) Session
How can you reduce RU (Request Units) consumption for queries? a) Reducing payload size b) Using selective projections c) Optimizing the partition key d) All of the above
Answers
QNo
Answer (Option with the text)
1
a) SELECT
2
b) Pagination of query results
3
b) WHERE
4
a) COUNT(*)
5
b) JSON documents
6
b) Referencing the property by name
7
b) .NET SDK
8
b) CreateContainerAsync()
9
c) CosmosAsyncContainer
10
b) By initializing a CosmosClient object
11
a) @azure/cosmos
12
a) ExecuteStoredProcedureAsync()
13
c) CREATE DOCUMENT
14
a) ReplaceItemAsync()
15
a) By using the partition key and id property
16
a) DeleteContainerAsync()
17
b) JavaScript
18
c) Performing operations within a single partition
19
a) Before or after an operation
20
b) To apply custom logic during queries
21
b) JavaScript
22
a) By specifying the trigger name during the operation