我正在尝试从Azure功能中将以下文档写入DocumentDb:
dynamic doc = new {
customer = "mycust",
version = "version2",
document = JObject.Parse("{\"prop1\": \"Some text.\"}")
}
await
_client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("db", "coll"),doc);
保存到documentdb后,我得到:
{
"customer": "mycust",
"version": "version2",
"document": {
"prop1": []
},
"id": "93ccb6d6-8829-4179-beba-606078f63dea"
}
缺少“某些文字”。在调试器中,它被正确解析。
答案 0 :(得分:0)
根据您的描述,我检查了这个问题并通过以下方法对其进行了测试,您可以参考它们:
#r "Newtonsoft.Json"
using System.Net;
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public static HttpResponseMessage Run(HttpRequestMessage req,out object outputDocument,TraceWriter log)
{
dynamic doc = new
{
customer = "mycust",
version = "version2",
document = JObject.Parse("{\"prop1\": \"Some text.\"}")
};
outputDocument=doc;
return req.CreateResponse(HttpStatusCode.OK, "success");
}
或参考Azure WebJobs SDK Extensions for DocumentDB并配置如下:
#r "Newtonsoft.Json"
using System.Net;
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.Azure.WebJobs.Extensions.DocumentDB;
public static HttpResponseMessage Run(HttpRequestMessage req,[DocumentDB("brucedb-2", "todoitem",ConnectionStringSetting = "brucedocumentdb-01_DOCUMENTDB")] out object outputDocument,TraceWriter log)
{
dynamic doc = new
{
customer = "mycust",
version = "version2",
document = JObject.Parse("{\"prop1\": \"Some text.\"}")
};
outputDocument=doc;
return req.CreateResponse(HttpStatusCode.OK, "success");
}
此外,您还可以利用Microsoft Azure DocumentDB Client Library并引用此类issue来向Azure DocumentDB添加新文档。