设置自定义 ID 时出现 Azure Cosmos / DocumentDB 问题 属性
Azure Cosmos / DocumentDB issue when setting custom id property
我想将文档插入到 documentDb。当我在插入文档之前没有添加自定义 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。
错误如下:"Can not convert Array to String."
" 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 函数中执行
如果您使用高于 9.0.1 的 Newtonsoft.Json
版本,可能会发生此错误。尝试将所有内容移回该版本,看看它是否有效。为了安全起见,我还建议使用 DocumentDB
软件包 1.13.2。
发生这种情况是因为主机是针对这些包的特定版本编译的,如果您尝试使用较新的版本,您可能会遇到像这样的微妙中断。有关我们如何解决此问题的详细信息,请参阅此问题:https://github.com/Azure/azure-webjobs-sdk-script/issues/992.
我想将文档插入到 documentDb。当我在插入文档之前没有添加自定义 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。
错误如下:"Can not convert Array to String."
" 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 函数中执行
如果您使用高于 9.0.1 的 Newtonsoft.Json
版本,可能会发生此错误。尝试将所有内容移回该版本,看看它是否有效。为了安全起见,我还建议使用 DocumentDB
软件包 1.13.2。
发生这种情况是因为主机是针对这些包的特定版本编译的,如果您尝试使用较新的版本,您可能会遇到像这样的微妙中断。有关我们如何解决此问题的详细信息,请参阅此问题:https://github.com/Azure/azure-webjobs-sdk-script/issues/992.