A gaming company stores player session data as JSON documents. Each document contains fields like sessionId, userId, startTime, and a varying set of optional fields such as deviceType or campaignId. The application needs to query sessions by userId and startTime range using SQL-like queries, and also by sessionId with low latency. Which Azure Cosmos DB API should the company choose?
The SQL API provides SQL query support over JSON documents and handles schema flexibility well.
Why this answer
The SQL (Core) API is the correct choice because it natively supports SQL-like queries over JSON documents, enabling efficient filtering by userId and startTime range. It also provides low-latency point reads by sessionId when a well-designed partition key (e.g., /userId) is used, and it offers automatic indexing of all JSON properties, including optional fields like deviceType or campaignId.
Exam trap
The trap here is that candidates may choose the MongoDB API because they assume 'SQL-like queries' require MongoDB's query language, but the Core API actually provides native SQL syntax and is the only Azure Cosmos DB API that supports SQL directly over JSON documents.
How to eliminate wrong answers
Option B (MongoDB API) is wrong because while it supports JSON documents and SQL-like queries via MongoDB's query language, it does not natively support the exact SQL syntax the application requires, and its indexing behavior differs from the Core API's automatic indexing of all fields. Option C (Table API) is wrong because it is designed for key-value storage with a flat schema and does not support nested JSON documents or SQL-like queries on varying optional fields. Option D (Gremlin (Graph) API) is wrong because it is optimized for graph traversal queries on entities and relationships, not for document-based queries on JSON fields like userId or startTime.