Launch price: every exam for $29.99 a year, for the first 300 buyers. See the price

CertStreak
Menu

Connect to Azure Cosmos DB for NoSQL by using the SDK and run queries

A worked example

Match

A Python application uses the azure-cosmos SDK to call container.query_items() against a container named products. The container's partition key path is /categoryId. You must set the correct query_items() argument for each requirement below.

Match each requirement to the query_items() argument that meets it. Each argument may be used once, more than once, or not at all.

  • Correct match: parameters.

    The parameters argument supplies @name values separately from the query text, which prevents injection. partition_key only controls routing and does not protect user-supplied values.

  • Correct match: enable_cross_partition_query.

    Because the filter does not include the partition key and results must span all categories, the query has to fan out to all partitions, which enable_cross_partition_query=True allows. partition_key would limit results to one category.

  • Correct match: partition_key.

    Passing partition_key="electronics" routes the query to one partition without editing the query. parameters would require adding a categoryId filter to the query text, which the requirement forbids.

  • Correct match: max_item_count.

    Setting max_item_count=50 limits each SDK page to 50 items or fewer; it does not guarantee exactly 50. enable_cross_partition_query affects which partitions are queried, not the page size.

Why

Parameterized queries pass values through the parameters argument, keeping user input out of the query text and preventing injection. When a query does not filter on the partition key but must cover all data, it becomes a cross-partition query, which you allow with enable_cross_partition_query=True. Specifying partition_key routes the query to a single partition without editing the query. Setting max_item_count=50 limits each SDK page to at most 50 items. offer_throughput sets RU/s when creating a container and is not used for these query requirements.

Practise this topic until it's automatic.

Ten questions a day, every answer explained, and misses that come back until you beat them.

Start free