我有以下存储过程,只能通过id找到一个对象.
function sample(id) {
var context = getContext();
var response = context.getResponse();
var collection = context.getCollection();
var findObject = "SELECT * FROM Objects o where o.userId='" + id +"'";
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
findObject,
function (err, feed, options) {
if (err) throw err;
// Check the feed and if empty, set the body to 'no docs found',
// else take 1st element from feed
if (!feed || !feed.length) throw new Error("Object not …Run Code Online (Sandbox Code Playgroud) 在以前的.Net控制台应用程序中,我们可以407通过在 中包含以下内容来避免代理错误app.config:
<system.net>
<defaultProxy useDefaultCredentials="true"/>
</system.net>
Run Code Online (Sandbox Code Playgroud)
.Net Core控制台应用程序没有app.config- 我们如何做同样的事情?
专门用于 Azure DocumentDB DocumentClient。
我正在进行一些研发以将产品目录移至 CosmosDB。
用最简单的术语来说,产品文档将具有:
制造商将登录该系统,并且只能查询他们自己的数据,因此ManufacturerId = SINGLE_VALUE每次查询都会有一个过滤器。
在查看 cosmos 文档时,re:选择正确的分区策略,似乎有 2 个要点。- 选择具有高基数的分区键 - 选择可以均匀分布数据的分区键。
在我上面的场景中,选择产品 ID 作为 PartitionKey 会非常极端……每个逻辑分区 1 个文档。另一方面,选择 Manufactuer 也不会很好,因为这不会导致均匀分布(有些制造商有 10 个产品,其他制造商有 100,000 个)
确保均匀分布的一种方法是采用 GUID 的前 4 个字符并将其用作 PartitionKey。(所以最多 4096 个分区)。根据我现有的数据集,这确实会导致数据的均匀分布。但我想知道这样做有什么缺点。
仅使用整个 productId 作为 PartitionKey(每个分区 1 个文档)是否有任何缺点,因为它们似乎表明对于存储用户配置文件的系统来说这是一种有效的方法。这种方法是否对在同一搜索中搜索多个产品有影响。
想象一下社交网络应用程序.用户关注其他用户和用户拍照.照片上有其他用户的标签.
我正在尝试为该应用程序获得有效的Cosmos数据库实现.我提供了SQL Server版本以及基准测试.
这是它的表格版本:
这是Gremlin查询:
g.V('c39f435b-350e-4d08-a7b6-dfcadbe4e9c5')
.out('follows').as('name')
.out('took').order(local).by('postedAt', decr).as('id', 'postedAt')
.select('id', 'name', 'postedAt').by(id).by('name').by('postedAt')
.limit(10)
Run Code Online (Sandbox Code Playgroud)
这是等效的SQL查询(实际上是linq):
Follows
.Where(f => f.FollowerId == "c39f435b-350e-4d08-a7b6-dfcadbe4e9c5")
.Select(f => f.Followees)
.SelectMany(f => f.Photos)
.OrderByDescending(f => f.PostedAt)
.Select(f => new { f.User.Name, f.Id, f.PostedAt})
.Take(10)
Run Code Online (Sandbox Code Playgroud)
该用户跟随136个用户,他们共同拍摄了257张照片.
SQL Server和Cosmos db都位于West Europe Azure位置.我在法国.我在Linpad上做了一些测试.
如何使用cosmos db更快更便宜地获取Feed?
注意:为了让RU充电,我正在使用Microsoft.Azure.Graph.但我也可以使用Gremlin.Net并得到类似的结果.
我有一个用于 Azure 函数的 Cosmos DB 触发器。我想将传入文档中的一些数据展平并写入(Azure)SQL Server。
有什么方法可以保证至少一次交货?
我查看了https://hackernoon.com/reliable-event-processing-in-azure-functions-37054dc2d0fc,它在事件中心事件触发的 Azure 函数的情况下提供了一些选项,但我不确定是否相同适用于导致触发器触发的 CosmosDB changefeed。
在 Cosmos DB Change Feed 站点https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed 上,它指出:
对文档的每次更改在更改提要中只出现一次,并且客户端管理其检查点逻辑。更改提要处理器库提供自动检查点和“至少一次”语义。
这是否意味着它实现了与事件中心相同(或类似)的检查点系统?
如果将断路器模式应用于此 CosmosDB 触发器到 Azure 函数的流程,如https://hackernoon.com/reliable-event-processing-in-azure-functions-37054dc2d0fc末尾所详述,断路器模式的工作方式是否相同?
azure reliable-message-delivery azure-functions azure-cosmosdb
我编写了一个函数来使用 Flutter/Dart 中 Azure Cosmos 数据库的查询来获取数据,但是它给出了错误:
response.body: {"code":"BadRequest","message":"Message: {\"Errors\":[\"The input content is invalid because the required properties - 'æ©; ' - are missing\"]}\r\nActivityId: f75a0c6e-2c8d-4f13-a020-6e3c13fa5458, Request URI: /apps/f4533d11-81e3-4512-b639-0f0475c10611/services/401c9130-a85e-46a6-8311-c2dc8e5070d6/partitions/b5d2a58d-1304-414b-92c7-10e7fa95f679/replicas/131768862196689298p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/2.0.0.0"}
I/flutter ( 5284): response.status: 400
Run Code Online (Sandbox Code Playgroud)
这是我的一段代码
final response = await http.post(
endpointResource,
// Query
body: query,
// Post new message
headers: {
HttpHeaders.AUTHORIZATION: authToken,
HttpHeaders.CONTENT_TYPE: "application/query+json",
//'content-type': 'application/json',
'Accept': 'application/json',
//c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
'x-ms-version': '2017-02-22',
'x-ms-date': date,
'x-ms-documentdb-isquery': 'true',
'x-ms-query-enable-crosspartition': 'true',
'x-ms-documentdb-query-enable-scan': 'true',
},
);
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能取回数据?
有没有一种方法可以将Microsoft.Azure.Documents.Document对象转换为我的类类型?
我用编写了一个Azure函数类CosmosDBTrigger。触发器接收的数组Microsoft.Azure.Documents.Document。我喜欢使用Document该类,以便可以访问有关记录本身的元数据,但是我也想以静态方式与我的类类型中的数据进行交互。
调用时,我看到了数据的JSON表示形式ToString。是否应该使用Newtonsoft将JSON手动转换为我的类类型?
我有一个查找活动,可从Blob中的容器获取值。我有一个foreach活动,它与查找活动有关
在设置下,其值为:
@activity('LookupMessageType').output.value
Run Code Online (Sandbox Code Playgroud)
我还有另一个在该foreach活动中运行的复制活动。它将数据从cosmos DB复制到Azure Data Lake。

这是源数据集中的查询:
select c.Tag, data.assetTag, data.timestamp, data.jsonVersion, data.messageType, data.speed from c join data in c.data
where (data.speed> item().speed_Value) AND
(data.timestamp >= '@{formatDateTime(addhours(pipeline().TriggerTime, -1), 'yyyy-MM-ddTHH:mm:ssZ' )}'
AND data.timestamp < '@{formatDateTime(pipeline().TriggerTime, 'yyyy-MM-ddTHH:mm:ssZ' )}')
Run Code Online (Sandbox Code Playgroud)
运行此管道时出现错误:
{
"errorCode": "2200",
"message": "Failure happened on 'Source' side. ErrorCode=UserErrorDocumentDBReadError,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=DocumentDb operation failed: Message: {\"errors\":[{\"severity\":\"Error\",\"location\":{\"start\":231,\"end\":235},\"code\":\"SC2005\",\"message\":\"'item' is not a recognized built-in function name.\"}]}\r\nActivityId: *redacted*, documentdb-dotnet-sdk/1.21.1 Host/64-bit MicrosoftWindowsNT/6.2.9200.0.,Source=Microsoft.DataTransfer.ClientLibrary.DocumentDb,''Type=Microsoft.Azure.Documents.BadRequestException,Message=Message: {\"errors\":[{\"severity\":\"Error\",\"location\":{\"start\":231,\"end\":235},\"code\":\"SC2005\",\"message\":\"'item' is not a recognized built-in function name.\"}]}\r\nActivityId: redacted, documentdb-dotnet-sdk/1.21.1 Host/64-bit MicrosoftWindowsNT/6.2.9200.0,Source=Microsoft.Azure.Documents.Client,''Type=System.Runtime.InteropServices.COMException,Message=Exception from HRESULT: 0x800A0B00,Source=,'",
"failureType": "UserError", …Run Code Online (Sandbox Code Playgroud) 我有一个带有 CosmosDB 输出绑定的 Azure 函数,如下所示:
public static class ComponentDesignHttpTrigger
{
[FunctionName("ComponentDesignInserter-Http-From-ComponentDesign")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "fromComponentDesign")] HttpRequest request,
[CosmosDB(
databaseName: StorageFramework.CosmosDb.DatabaseId,
collectionName: Storage.ComponentDesignCollectionId,
ConnectionStringSetting = "CosmosDBConnection")] out ComponentDesign componentDesignToInsert,
ILogger log)
{
var requestBody = new StreamReader(request.Body).ReadToEnd();
componentDesignToInsert = JsonConvert.DeserializeObject<ComponentDesign>(requestBody);
return new OkObjectResult(componentDesignToInsert);
}
}
Run Code Online (Sandbox Code Playgroud)
在这个函数componentDesignToInsert中,函数执行完成后会自动序列化并放入 CosmosDB。但是默认的序列化不会把东西放在camelCase中。为此,Json.NET 允许您提供自定义序列化程序设置,如下所示:
var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
var json = JsonConvert.SerializeObject(yourObject, settings);
Run Code Online (Sandbox Code Playgroud)
但我不确定如何将它与我的输出绑定集成。我怎样才能做到这一点?
azure json.net azure-functions azure-cosmosdb azure-functions-core-tools
查询 Cosmos DB(表存储 API)以获取存储中的“下一个”项目的好策略是什么?“下一个”定义为上次调用未返回的前 1 个项目。上次调用返回的项目保存在内存中。使用 .NET 框架,C#。表预计可容纳大约 200 万个条目,因此不首选表扫描。:)
表存储看起来像这样:分区键(多个值的组合):“0000/00/01/2020-01-11”。例如,行键单个 int 值 1。行包含其他字符串数据。
所以键值对(分区键和行键)如下所示。该应用程序需要大量读取,但不一定使用日志尾模式 ( https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-design-guide#log-tail-pattern ) .
0000/00/01/2020-01-11,1,aaa,x
0000/00/01/2020-01-11,2,aaa,y
0000/00/01/2020-01-11,3,aaa,z
0000/00/01/2020-01-11,4,bbb,x
0001/00/01/2020-01-11,5,aaa,x
0001/00/01/2020-01-11,6,ddd,x
Run Code Online (Sandbox Code Playgroud)
(注意底部的两个实体将在不同的分区中,因此“aaa,x”存在于两个分区中)。
所以我认为查询只获得一项是
TableQuery<MyClass> query = new TableQuery<MyClass>()
.Where(TableQuery.GenerateFilterCondition("0000/00/01/2020-01-11", QueryComparisons.Equal, "aaa")).Take(1);
Run Code Online (Sandbox Code Playgroud)
如果那是代码正确,并返回“aaa,x”如何确保后续查询得到“aaa,y”,下一次得到“aaa,z”,下一次得到“bbb,x”和下一个将在同一分区中再次获得“aaa,x”?
如果制作富对象没有意义,而是直接查询 REST API 并可能保留上次在另一个表中使用的项目和两个表之间的外部联接或其他过滤条件,我愿意设计那个方向。
谢谢!
azure azure-table-storage azure-cosmosdb azure-cosmosdb-tables