簡體   English   中英

Azure node.js 中的 Azure 與 Cosmos DB 綁定不會將屬性注入 sqlQuery

[英]Azure function in node.js with Cosmos DB binding doesn't get properties injected into sqlQuery

我有以下配置。

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": ["post"],
      "route": "migrate/events/"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "name": "documents",
      "type": "cosmosDB",
      "direction": "in",
      "databaseName": "MyDatabase",
      "collectionName": "{name}",
      "sqlQuery": "SELECT * FROM c where c._ts >= {ts} ORDER BY c._ts OFFSET 0 LIMIT 3",
      "connectionStringSetting": "CosmosDBConnection"
    },
    ...
}

我使用以下請求正文調用端點。

{
    "name": "MyEvents",
    "ts": 1620712053
}

在 function 中,我可以看到req.body上的屬性可用,但documents數組為空。

{ts}屬性替換為實際值會得到一個包含 3 個文檔的數組。

"sqlQuery": "SELECT * FROM c where c._ts >= 1620712053 ORDER BY c._ts OFFSET 0 LIMIT 3",

因此,它適用於注入{name}collectionName但不適用於應注入{ts}sqlQuery

我也嘗試過使用 routedata "route": "migrate/events/{name}/{ts}"並查詢{Query.ts}但沒有任何運氣。

我之前遇到過這個問題,目前這在sqlQuery的綁定中是被阻止的。 正如here提到的

“為了防止注入攻擊,在將 SqlQuery 屬性中使用的任何綁定字符串發送到您的文檔數據庫之前,都將替換為 SqlParameter。”

您可以按照這種替代方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM