[英]Azure function cosmos db sql query with ARRAY CONTAINS on string array
I' using Azure Functions and Cosmos DB with javascript to make the following query:我使用 Azure 函数和 Cosmos DB 与 javascript 进行以下查询:
SELECT * FROM Posts p WHERE ARRAY_CONTAINS(p.audience, "username_1")
It works when I try it on the website but requires the quotes.当我在网站上尝试它时它可以工作,但需要引号。 However, in my function.json
I have:然而,在我的function.json
我有:
{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get"
],
"route": "getFeed/{username}"
},
{
"name": "res",
"type": "http",
"direction": "out"
},
{
"type": "cosmosDB",
"name": "userItem",
"databaseName": "TwitterClone",
"collectionName": "Users",
"connectionStringSetting": "CosmosDBConnection",
"direction": "in",
"sqlQuery" : "SELECT * FROM Posts p WHERE ARRAY_CONTAINS(p.audience, {username})"
}
],
"disabled": false
} }
And I just get no results.我只是没有得到任何结果。 I guess it is because of the lack of quotes around {username}
...So how do I add quotes or get over the issue?我想这是因为{username}
周围没有引号......那么我该如何添加引号或解决这个问题?
Here is an example document:这是一个示例文档:
{
"author_username": "username_2",
"audience": [
"username_1",
"username_3"
],
}
Can you try this?你能试试这个吗?
SELECT * FROM posts p where ARRAY_CONTAINS(p.auience, {{username:{username}}}, true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.