I want to pass array as a param to SqlQuerySpec to be able to use it in the IN expression when building query for azure cosmos db. What i'm trying to do is something like we do with regular (string, int etc) params:
private SqlQuerySpec BuildQuery(IEnumerable<string> exclTypes)
{
var queryText = "SELECT * FROM root r WHERE r.Type NOT IN (@types)";
var parameters = new SqlParameterCollection{new SqlParameter("@types", exclTypes.ToArray())};
return new SqlQuerySpec()
{QueryText = queryText, Parameters = parameters};
}
But that doesn't work in such way. Any other ways I can pass array as a param? Thanks.
In the Azure Cosmos DB blade, locate and select the Data Explorer link on the left side of the blade. In the Data Explorer section, expand the NutritionDatabase database node and then expand the FoodCollection container node. Within the FoodCollection node, select the Items link. View the items within the container.
The Azure Cosmos DB API for NoSQL supports querying documents using SQL.
Your query should look something like this:
SELECT * FROM root r WHERE ARRAY_CONTAINS(@types, r.Type) <> true
then you can pass @types
as array and check if that array contains value you have in property r.Type
in your document.
refs:
https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sql-query-reference#bk_array_contains https://github.com/Azure/azure-documentdb-node/issues/156
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With