标签: azure-cosmosdb

从Azure DocumentDB导出数据

Azure中有一个选项可以从DocumentDB导出现有的集合吗?

我只能看到一个导入选项.

azure azure-cosmosdb

8
推荐指数
3
解决办法
1万
查看次数

如何实例化ResourceResponse <Document>

我试图模拟一个返回的调用ResourceResponse<Document>,但我无法实例化该类型.是否有工厂类可以实例化它或其他方式这样做?

编辑

var response = new ResourceResponse<Document>();

类型'Microsoft.Azure.Documents.Client.ResourceResponse'没有定义构造函数

c# moq azure-cosmosdb

8
推荐指数
1
解决办法
2144
查看次数

为什么DocumentDb在测试场景中运行时偶尔会失败

我们有一个目前正在开发的项目,我们使用Azure DocumentDb作为数据存储库.它一直很好,我真的很喜欢它如何工作以及它如何实现快速开发,但最近我们的集成测试已经开始失败.

每次测试运行时,我们的集成测试都会在数据库中创建和拆除集合.我想知道它的这个过程是否以某种方式"破坏"了数据库.

我已经将我们的项目剥离到了它的骨架并在这里检查了它:https://github.com/DamianStanger/DocumentDbDemo

当我运行测试时,我收到以下错误:

System.AggregateException : One or more errors occurred.
  ----> Microsoft.Azure.Documents.DocumentClientException : Message:  {"Errors":["Resource with specified id or name already exists"]}
ActivityId: e273b9d6-b571-43d3-9802-c7d7c819a3f0, Request URI: /apps/c9c8f510-0ca7-4702-aa6c-9c596d797367/services/507e2a70-c787-437c-9587-0ff4341bc265/partitions/ae4ca317-e883-4419-84f9-c8d053ffc73d/replicas/131159218637566393p
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at DocumentDbDemo.Data.AggregateRepository.CreateCollectionIfNotExists() in K:\_code\VisualStudio\DocumentDbPerfTests\DocumentDbDemo.Data\AggregateRepository.cs:line 32
   at DocumentDbDemo.Data.AggregateRepository..ctor(ConfigFactory configFactory) in K:\_code\VisualStudio\DocumentDbPerfTests\DocumentDbDemo.Data\AggregateRepository.cs:line 19
   at DocumentDbDemo.Data.Tests.AggregateRepositoryTests.ShouldReturnNullIfNotFound() in K:\_code\VisualStudio\DocumentDbPerfTests\DocumentDbDemo.Data.Tests\AggregateRepositoryTests.cs:line 24
--DocumentClientException
Run Code Online (Sandbox Code Playgroud)

AggregateRepository.cs_client.ReadDocumentCollectionAsync内的调用失败引起的.我不明白.代码中的异常是首先检查集合是否存在(它确实存在),然后如果不存在则会创建它.显然,创建将失败,因为集合存在!

第二种类型的失败是:

System.AggregateException : One or more errors occurred.
  ----> Microsoft.Azure.Documents.DocumentClientException : Message: {"Errors":["Owner resource does not exist"]} …
Run Code Online (Sandbox Code Playgroud)

c# azure azure-cosmosdb

8
推荐指数
1
解决办法
1474
查看次数

Azure Cosmos DB - Mongo API是否支持聚合

我希望使用cosmosdb来存储以文档为中心的设计中布置的时间序列数据.使用官方的mongodb驱动程序,我试着写一些简单的聚合语句; 但是,我收到的错误表明$ unwind和$ group不受支持.鉴于cosmosdb被吹捧为mongodb的替代品,我错过了一个步骤,或者聚合不是支持的功能.

retrieve.Aggregate().Unwind(i => i.Observations).Group(new BsonDocument {
        {"_id", "$Observations.Success"},
        {"avg", new BsonDocument{
        {"$avg", "$Observations.Duration"}
        }}
    }).ToList();
Run Code Online (Sandbox Code Playgroud)

c# mongodb mongodb-.net-driver azure-cosmosdb

8
推荐指数
2
解决办法
1377
查看次数

什么是Azure中的EUAP区域?

Azure中的某些区域被称为EUAP区域,但是我无法找到任何关于这意味着什么的定义.EUAP代表什么?

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.documents.locationnames.centraluseuap?view=azure-dotnet

从上面的链接:

Azure Cosmos数据库服务中Azure Central US EUAP区域的名称.

azure azure-cosmosdb

8
推荐指数
1
解决办法
1797
查看次数

Cosmos DB Emulator:无法获得优惠的授权标头

我将Azure Cosmos DB Emulator从版本1.22 升级到2.0.现在,当我转到本地数据资源管理器时,资源管理器选项卡中没有任何内容加载,我看到错误

无法获得商品的授权标头:{"readyState":4,"responseText":"{\"code \":\"InternalServerError \",\"message \":\"处理此请求时发生未知服务器错误.\r \nActivityId:48afdb03-e04b-4a5e-b568-e268c32eb10f,Microsoft.Azure.Documents.Common/2.0.0.0 \"}","responseJSON":{"code":"InternalServerError","message":"Unknown处理此请求时发生服务器错误.\ r \nActivityId:48afdb03-e04b-4a5e-b568-e268c32eb10f,Microsoft.Azure.Documents.Common/2.0.0.0"},"status":500,"statusText":"error" }

我尝试重新安装它,重新启动PC,并以管理员身份运行它.

我该怎么做才能解决这个问题?

.net azure .net-core azure-cosmosdb

8
推荐指数
1
解决办法
991
查看次数

使用存储过程的Azure documentdb批量插入

嗨我正在使用16个集合来插入大约3-4百万个json对象,范围从每个对象5-10k.我使用存储过程来插入这些文件.我有22个容量单位.

function bulkImport(docs) {
    var collection = getContext().getCollection();
    var collectionLink = collection.getSelfLink();

    // The count of imported docs, also used as current doc index.
    var count = 0;

    // Validate input.
    if (!docs) throw new Error("The array is undefined or null.");

    var docsLength = docs.length;
    if (docsLength == 0) {
        getContext().getResponse().setBody(0);
    }

    // Call the CRUD API to create a document.
    tryCreateOrUpdate(docs[count], callback);

    // Note that there are 2 exit conditions:
    // 1) The createDocument request was not accepted. 
    // …
Run Code Online (Sandbox Code Playgroud)

bulkinsert azure azure-cosmosdb

7
推荐指数
2
解决办法
6712
查看次数

从.net调用DocumentDb存储过程

我有以下存储过程,只能通过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)

c# stored-procedures azure azure-cosmosdb

7
推荐指数
1
解决办法
3100
查看次数

Azure DocumentDB偶尔会抛出SocketException/GoneException

更新(2/8/17):

见下面的答案.

更新(2/7/17):

我发现重启可以让我从Visual Studio 2015成功运行Web应用程序,并多次点击端点.但是,当我停止应用程序并重新启动它时,它很可能会失败.然后它将重复失败,直到我重新启动计算机.重启VS'15还不够好.

一旦它开始失败,从VS代码运行应用程序或从命令行运行dotnet.exe表现出相同的行为.

原始邮寄:

我们有一个微服务系统设置,可以从几个API和Azure Functions调用DocumentDB集合.它与API端(嵌套在一起)间歇性地失败.据我们所知,只要它偶尔起作用,调用它的代码大多是正确的.Azure功能可以正常工作.SocketExceptionGoneException

编辑澄清:"间歇性地",我的意思是它可能每天短暂工作一次或两次,然后在没有通话的剩余时间进入失败状态.这不像每100个左右的呼叫失败一样.这更像是1或2次成功呼叫后的不间断故障.

通过编写一个简单的控制台应用程序来从DocumentDB中读取并将结果打印到Debug输出,我能够重新创建相同的异常.这运行一两次没有任何问题,然后每次都开始抛出以下异常.它会在有几个小时之前执行此操作,然后再拨打几个电话,然后重新投入.

虽然下面的测试器是原始的,但主API充分利用了vNext项目结构.它使用单个DocumentClient进行连接(通过本机DI注入),它几乎完全异步从控制器一直到调用db的服务层.我们使用一个单独的库来管理对DocumentDB的访问(如果它们不存在则创建集合,添加扩展方法,简单的CRUD操作等),但是如下所示直接调用会产生相同的结果.

我注意到的一件事是它对于DocumentDB客户端("Microsoft.Azure.DocumentDB.Core": "1.0.0")的核心版本而言比在net46版本中更成功.由于其他库,我们的API需要4.6.

我可以在多台机器,多个网络,多种连接类型上重新创建它.

问题:为什么我们会收到此异常,我们如何解决?

Azure信息:

  • 美国东部2
  • 1000 RU/s
  • 标准层
  • 会话一致性
  • 懒惰索引策略:

    {"indexingMode":"lazy","automatic":true,"includedPaths":[{"path":"/*","indices":[{"kind":"Range","dataType":"Number ",""precision": - 1},{"kind":"Hash","dataType":"String","precision":3}]}],"excludedPaths":[]}

考试班

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Linq;
using Newtonsoft.Json;

namespace TestConnection
{
    public class Program
    {
        public static void Main(string[] args)
        {
            try
            {
                using (var client = new DocumentClient(
                    new Uri("https://<our-docdb-name>.documents.azure.com:443/"),
                    "our access key",
                    new ConnectionPolicy
                    {
                        ConnectionMode …
Run Code Online (Sandbox Code Playgroud)

c# azure .net-core azure-cosmosdb

7
推荐指数
1
解决办法
2098
查看次数

在CosmosDB中索引数组

为什么CosmosDB默认不进行索引?默认索引路径是

"path": "/*"
Run Code Online (Sandbox Code Playgroud)

这不是指"索引一切"吗?不是"除了数组之外的所有索引".

如果我将我的数组字段添加到索引中,如下所示:

"path": "/tags/[]/?"
Run Code Online (Sandbox Code Playgroud)

它将工作并开始索引特定的数组字段.

但我的问题是为什么不"索引一切"索引一切?

编辑:这是一篇描述我所看到的行为的博客文章.http://www.devwithadam.com/2017/08/querying-for-items-in-array-in-cosmosdb.html Array_Contains查询非常慢,显然没有使用索引.如果您明确地将相关字段添加到索引中,那么查询很快(显然它们开始使用索引).

azure azure-cosmosdb

7
推荐指数
1
解决办法
1556
查看次数