我在cosmo db中定义了一个函数,定义如下。在编辑器中,查询有效,但是当我运行该函数时,它返回 500 Internal Server Error 。
我的文档:
{
"user": "428",
"year": "2019",
"id": "1",
"dataType": "LineString",
"dataCategory": "realPath",
"tripNumber": "A02232",
"currentCoordinate": [
13.845224,
43.02356
],
"deliveries": [
{
"devNumber": "001",
"unloadSeq": "1",
"currentDev": "1",
"email": "punto1@mail.it",
"targetCoordinate": [
13.965224,
43.95356
],
"coordinates": [
[
13.790663,
43.028926
],
[
13.791447,
43.029169
],
[
13.792198,
43.029561
],
[
13.793775,
43.030549
],
[
13.794601,
43.0312
],
[
13.795577,
43.031835
],
[
13.797047,
43.032737
],
[
13.797605,
43.033153
],
[
13.798249,
43.033647
],
[
13.798732,
43.03367
],
[
13.800126,
43.033678
],
[
13.801661,
43.033725
],
[
13.802755,
43.034172
],
[
13.845224,
43.02356
]
]
},
{
"devNumber": "008",
"unloadSeq": "2",
"currentDev": "0",
"email": "punto2@mail.it",
"targetCoordinate": [
13.995224,
43.99356
],
"coordinates": []
}
],
"_rid": "3pRjAIHZRNUBAAAAAAAAAA==",
"_self": "dbs/3pRjAA==/colls/3pRjAIHZRNU=/docs/3pRjAIHZRNUBAAAAAAAAAA==/",
"_etag": "\"00006b08-0000-0000-0000-5c2def460000\"",
"_attachments": "attachments/",
"_ts": 1546514246
}
在编辑器中查询没问题:
SELECT * FROM Trip c where ARRAY_CONTAINS(c.deliveries, {"currentDev": "1", "email": "punto1@mail.it"}, true)
在function.json中查询不起作用:
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
],
"route": "getRoutes/{emailpar}"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"type": "cosmosDB",
"name": "inDocuments",
"databaseName": "cdb-01",
"collectionName": "myCollection",
"connectionStringSetting": "mpn_COSMOSDB",
"direction": "in",
"sqlQuery": "SELECT * FROM Trip c where ARRAY_CONTAINS(c.deliveries, {currentDev: '1', email: {emailpar}}, true)"
}
]
}
我认为通过括号{}定义数组中要搜索的参数和对象是语法问题。
答案 0 :(得分:0)
您需要对sql查询字符串的非参数字符串插值对象进行转义。您可以通过在每个引用中添加一个大括号来做到这一点。
这意味着您的查询字符串必须为:
SELECT * FROM Trip c where ARRAY_CONTAINS(c.deliveries, {{currentDev: '1', email: {emailpar}}}, true)