我使用类型化的DocumentQuery从Azure DocumentDb的集合中读取文档.
from f in client.CreateDocumentQuery<MyModel>(Collection.SelfLink) select f
Run Code Online (Sandbox Code Playgroud)
因为我找不到如何设置neccesarry自定义json转换器的方法,所以它抛出了这个例子:
无法创建AbstractObject类型的实例.Type是接口或抽象类,无法实例化.
通常你会做这样的事情来使它工作:
var settings = new JsonSerializerSettings();
settings.Converters.Add(new MyAbstractConverter());
client.SerializerSettings = settings;
Run Code Online (Sandbox Code Playgroud)
DocumentClient没有任何SerializerSettings.所以问题是,如何在将json数据反序列化到我的模型时告诉DocumentDB客户端它必须使用自定义转换器?
有没有办法递归调用存储过程(甚至UDF,如果这将工作)对DocumentDB文档?
我们有一个看起来像这样的文档:
{
"docID" : "my_id",
"owner" : "fred",
"items" : [
{
"itemID" : "1",
"type" : "item",
"value" : 3
},
{
"itemID" : "2",
"type" : "group",
"items" : [
{
"itemID" : "2.1",
"type" : "group",
"items" : [
{
"itemID" : "2.1.1",
"type" : "item",
"value" : 2
},
{
"itemID" : "2.1.2",
"type" : "item",
"value" : 4
}
]
},
{
"itemID" : "2.2",
"type" : "item",
"value" : 1
}
]
} …Run Code Online (Sandbox Code Playgroud) 我一直在为受限制的DocumentDB客户端调用编写非常详细的重试逻辑.
下面的示例是10次重试尝试的常见示例.
我的问题有两个方面: 这是最好的做法,是否有一种不那么冗长的方式来处理这个问题?我看到有一个Microsoft.Azure.Documents.Client.TransientFaultHandling nuget包应该用更少的代码实现相同的结果,但我在StackOverflow或Google上找不到任何示例,似乎没有任何明确的文档可用来自微软.
int maxRetryAttempts = 10;
while (maxRetryAttempts > 0)
{
try
{
// Attempt to call DocumentDB Method
// ---[DocumentDB Method Here]---
}
catch (DocumentClientException de)
{
if (de.StatusCode.HasValue)
{
var statusCode = (int)de.StatusCode;
if (statusCode == 429 || statusCode == 503)
{
//Sleep for retry amount
Thread.Sleep(de.RetryAfter);
//Decrement max retry attempts
maxRetryAttempts--;
}
}
}
catch (AggregateException ae)
{
foreach (Exception ex in ae.InnerExceptions)
{
if (ex is DocumentClientException)
{
var documentClientException = ex …Run Code Online (Sandbox Code Playgroud) 我有一个自定义表单对象结构,我成功使用mongodb.
我一直在研究用DocumentDb替换Mongo的可能性.
我的类结构由不同类型的控件继承的基本控件组成.例如文本框控件,下拉控件
在mongo我使用鉴别器字段来存储实际类型,在c#DocumentDb驱动程序中我看不到找到相同的功能.
下面是mongo如何存储我的类结构的示例.
{
"_t" : "TextboxControl",
"LabelText" : "Location of incident",
"IsRequired" : true,
"_id" : "cbe059d9-b6a9-4de2-b63b-14d44b022e37"
}
Run Code Online (Sandbox Code Playgroud)
在documentdb中,结构看起来像
{
"LabelText": "Location of incident",
"IsRequired": true,
"id": "cbe059d9-b6a9-4de2-b63b-14d44b022e37"
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,mongo版本具有一个"_t"属性来说明实际类型,然后在我读取数据时使用它来创建正确的类型.在documentdb版本中,它只是一个字段类型
尝试在沙箱中学习查询语法(https://www.documentdb.com/sql/demo)
SELECT food.id FROM food JOIN t in food.tags WHERE t.name = "oil"
Run Code Online (Sandbox Code Playgroud)
这有效,但是如果我想获得整个文档怎么办,所以我试过了
SELECT food.* FROM food JOIN t in food.tags WHERE t.name = "oil"
Run Code Online (Sandbox Code Playgroud)
和
SELECT * FROM food JOIN t in food.tags WHERE t.name = "oil"
Run Code Online (Sandbox Code Playgroud)
并得到错误:
{
"errors": [
{
"severity": "Error",
"location": {
"start": 7,
"end": 8
},
"code": "SC2040",
"message": "'SELECT *' is only valid with a single input set."
}
]
}
Run Code Online (Sandbox Code Playgroud)
如何获得整个文件?
我想使用自定义JsonSerializerSettings使用DocumentDb API创建文档。谁能告诉我该怎么做?
我尝试设置
JsonConvert.DefaultSettings = () => {
return new JsonSerializerSettings() {
ContractResolver = new CamelCasePropertyNameContractResolver()
};
};
Run Code Online (Sandbox Code Playgroud) 我想使用select query从azure-cosmos DB中获取100多条记录.
我正在编写存储过程并使用select查询来获取记录.
SELECT * FROM activities a
虽然有超过500条记录,但我只获得了100条记录.我可以使用Azure提供的设置配置获取所有记录.
我想使用查询或存储过程执行相同的操作.我怎样才能做到这一点 ??
请提出需要完成的更改建议.
使用Visual Studio 2017,我创建了一个新的Azure功能应用程序.我添加了一个函数,其中一个属性参数是ConnectionStringSetting.这应该是存储在某处的设置的参考,但我无法弄清楚我的生活在哪里.
我试图把它放在local.settings.json文件中,没有运气.我试图添加一个app.config/ appSettings部分,但也没有做任何事情.
我在这个方法中没有做任何疯狂的事情:
namespace MyFunctions
{
public static class TestUpdated
{
[FunctionName("DocumentUpdated")]
public static void Run(
[CosmosDBTrigger("mydb", "somecollection",
ConnectionStringSetting = "DbConnString",
LeaseCollectionName = "lease-test-trigger",
CreateLeaseCollectionIfNotExists = true)]
IReadOnlyList<Document> documents, TraceWriter log)
{
log.Info("Documents modified " + documents.Count);
log.Info("First document Id " + documents[0].Id);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的所有扩展和nuget包都是最新版本.
那么,你如何设置连接字符串?这是几个小时尝试不同的事情,没有任何作用.
在我学习如何使用Cosmos DB的图形时,我发现了两个Microsoft教程:
虽然我使用相同的查询,但它的执行不同.
使用Gremlin.Net,它立即执行.我经常(我会说70%的时间)得到一个RequestRateTooLargeException.如果我理解正确,这意味着我一直达到我选择的400RU/s限制.但是,当查询进入低谷时,它的速度是Microsoft.Azure.Graph解决方案的两倍.
实际上,使用Micorosft.Azure.Graph,我必须调用ExecuteNextAsync一个循环,一次返回一个结果.
所以问题是:
1°)我应该使用哪种方法来获得更好的性能?
2°)我怎么知道我的查询的RU所以我可以微调它?
3°)是否可以提高现有集合的吞吐量?
更新
问题3,我发现在我的数据库的"数据资源管理器"刀片中,我的图表有一个"Scale&Settings",我可以更新吞吐量.
Update2
问题2,我们无法在使用第一种方法(Gremlin.Net)时收取RU,但Microsoft.Graph方法ExecuteNextAsync返回FeedResponse带有字段的a RequestCharge.
我已经在Azure中使用Mongo API创建了一个Cosmos DB数据库。我已经创建了客户端并进行了如下配置-
_mongoDbConnectionString = configuration["MongoDBConnectionString"];
_databaseName = configuration["MongoDBName"];
_client = new MongoClient(_mongoDbConnectionString);
_database = _client.GetDatabase(_databaseName);
_collectionName = configuration["MongoDBCollectionName"];
Run Code Online (Sandbox Code Playgroud)
然后尝试写数据
_database.GetCollection<dynamic>(_collectionName).InsertOne(data);
Run Code Online (Sandbox Code Playgroud)
它因错误而失败-
在使用CompositeServerSelector {Selectors = MongoDB.Driver.MongoClient + AreSessionsSupportedServerSelector,LatencyLimitingServerSelector {AllowedLatencyRange = 00:00:00.0150000}}选择服务器的30000毫秒后发生超时。群集状态的客户端视图为{ClusterId:“ 1”,ConnectionMode:“ ReplicaSet”,类型:“ ReplicaSet”,状态:“ Disconnected”,服务器:[{ServerId:“ {ClusterId:1,端点:”未指定/ botframeworkcosmos。 documents.azure.com:10255“}”,端点:“ Unspecified / botframeworkcosmos.documents.azure.com:10255”,状态:“ Disconnected”,类型:“ Unknown”,HeartbeatException:“ MongoDB.Driver.MongoConnectionException:异常---> System.Net.Internals,打开服务器连接时发生。
我尝试了此解决方案-使用CompositeServerSelector选择服务器30000ms后发生超时,但是它不起作用。
我还尝试过设置这样的SSL策略来配置客户端-
_mongoDbConnectionString = configuration["MongoDBConnectionString"];
_databaseName = configuration["MongoDBName"];
MongoClientSettings settings = MongoClientSettings.FromUrl(
new MongoUrl(_mongoDbConnectionString)
);
settings.SslSettings =
new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 };
_client = new MongoClient(settings);
_database = _client.GetDatabase(_databaseName);
_collectionName = …Run Code Online (Sandbox Code Playgroud) azure-cosmosdb ×10
azure ×4
c# ×4
.net ×1
asp.net-core ×1
gremlin ×1
inheritance ×1
json ×1
json.net ×1
mongodb ×1
nosql ×1
polymorphism ×1
recursion ×1