I noticed that when querying items in a Cosmos DB database, the code sample on Microsoft Docs doesn't require a partitionKey. Why is that? I can certainly imagine scenarios where we may want to run a query on the whole database but whenever possible wouldn't it be more efficient and faster to limit the query to a particular partition?
Here's the code from the Docs:
string query = "SELECT * FROM products p WHERE p.category = @category"
var query = new QueryDefinition(query)
.WithParameter("@category", "gear-surf-surfboards");
using FeedIterator<Product> feed = container.GetItemQueryIterator<Product>(
queryDefinition: query
);
Here's the link to Microsoft Docs: https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/quickstart-dotnet?pivots=devcontainer-codespace#query-items
partitionKeyis not defined in the query. In the example, the query parameter just happened to be the property used aspartitionKey. The query parameter could've been some other property that is not the partition key for the container. For example, it could've beenstring query = "SELECT * FROM products p WHERE p.productName = @productName"