设置自定义标识属性时出现Azure Cosmos / DocumentDB问题

时间:2017-09-20 15:04:55

标签: azure azure-functions azure-cosmosdb

我想将文档插入documentDb。当我在插入doc之前没有添加自定义id属性时,这工作正常。

实施例

foreach (dynamic doc in docs)
{
    if (doc != null)
    {

        doc.id = Convert.ToString(doc.myCustomId); // myCustomId is an integer
        var addedDoc = await dbClient.UpsertDocumentAsync(collectionUri, doc);
        addedDocuments.Add(addedDoc);
    }
}

当我删除doc.id =>该文档添加了一个guid作为id。

错误如下:“无法将数组转换为字符串。”

"   bei Newtonsoft.Json.Linq.JToken.op_Explicit(JToken value)\r\n   bei Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)\r\n   bei Newtonsoft.Json.Linq.JToken.ToObject[T]()\r\n   bei Microsoft.Azure.Documents.JsonSerializable.GetValue[T](String propertyName)\r\n   bei Microsoft.Azure.Documents.Resource.get_Id()\r\n   bei Microsoft.Azure.Documents.Client.DocumentClient.ValidateResource(Resource resource)\r\n  

代码在Azure功能

中执行

1 个答案:

答案 0 :(得分:3)

如果使用高于9.0.1的Newtonsoft.Json版本,则会发生此错误。尝试将所有内容移回该版本,看看它是否有效。我还建议使用DocumentDB软件包1.13.2以确保安全。

这是因为主机是针对这些软件包的特定版本编译的,如果你尝试使用更新的版本,你可以得到这样的细微内容。有关我们如何解决此问题的详细信息,请参阅此问题:https://github.com/Azure/azure-webjobs-sdk-script/issues/992

相关问题