简体   繁体   English

Azure Functions SDK

[英]Azure Functions SDK

After upgrading to 1.0.1 CLI tools without any code changes, I suddenly started to get the following error: 升级到1.0.1 CLI工具而没有任何代码更改后,我突然开始出现以下错误:

ResizeImage: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ResizeImage'. 
Microsoft.Azure.WebJobs.Extensions.DocumentDB:
 'Id' is required when binding to a DocumentClient property.

The following code: 如下代码:

[FunctionName(nameof(ResizeImage))]
public static async Task RunAsync([BlobTrigger("profile-pictures/{name}")] CloudBlockBlob myBlob, string name, [DocumentDB(databaseName: "x", collectionName: "UserProfile", CreateIfNotExists = true)] DocumentClient client, [Blob("profile-pictures/resized-{name}", FileAccess.ReadWrite)] CloudBlockBlob resizedBlob, TraceWriter log)

I thought Id is optional? 我以为id是可选的? At least that's what the docs says. 至少文档就是这样说的。

According to the docs: 根据文档:

The properties id and sqlQuery cannot both be specified. 不能同时指定属性id和sqlQuery。 If neither id nor sqlQuery is set, the entire collection is retrieved. 如果未设置id或sqlQuery,则将检索整个集合。

The generated json: 生成的json:

{
  "bindings": [
    {
      "type": "blobTrigger",
      "path": "profile-pictures/{name}",
      "direction": "in",
      "name": "myBlob"
    },
    {
      "type": "documentDB",
      "databaseName": "x",
      "collectionName": "UserProfile",
      "createIfNotExists": true,
      "direction": "out",
      "name": "client"
    },
    {
      "type": "blob",
      "path": "profile-pictures/resized-{name}",
      "direction": "inout",
      "name": "resizedBlob"
    }
  ],
  "disabled": false,
  "scriptFile": "..\\X.Functions.dll",
  "entryPoint": "X.Functions.ResizeImage.RunAsync"
}

I'm using 1.0.0 SDK 我正在使用1.0.0 SDK

I thought Id is optional? 我以为id是可选的? At least that's what the docs says. 至少文档就是这样说的。

Yes, id is optional. 是的,id是可选的。 But according to the document of Azure Functions Cosmos DB bindings . 但是根据Azure Functions Cosmos DB的文档绑定 We need to use IEnumerable<dynamic> as the binding type. 我们需要使用IEnumerable <dynamic>作为绑定类型。 Please change your code as following. 请按以下方式更改您的代码。

[DocumentDB(...)] IEnumerable<dynamic> documents

You will get all the documents from the collection. 您将从集合中获取所有文档。 I tested it and it worked fine on my side. 我对其进行了测试,结果对我而言效果很好。

In addition, the direction should be changed to in if you want to get data from DocumentDB. 另外,如果要从DocumentDB获取数据,则应将方向更改为in。

"direction": "in"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM