标签: azure-cosmosdb

动态属性名称作为字符串

使用 DocumentDB 创建新文档时,我想动态设置属性名称,目前我设置SomeProperty,如下所示:

await client.CreateDocumentAsync("dbs/db/colls/x/" 
   , new { SomeProperty = "A Value" });
Run Code Online (Sandbox Code Playgroud)

,但我想SomeProperty从字符串中获取属性名称,以便我可以使用同一行代码访问不同的属性,如下所示:

void SetMyProperties()
{
    SetMyProperty("Prop1", "Val 1");
    SetMyProperty("Prop2", "Val 2");
}

void SetMyProperty(string propertyName, string val)
{
    await client.CreateDocumentAsync("dbs/db/colls/x/" 
       , new { propertyName = val });
}
Run Code Online (Sandbox Code Playgroud)

这有可能吗?

c# dynamic azure azure-cosmosdb

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

CosmosDB 按值将结果排序到数组中

我有一些 CosmosDB 文档,如下所示

{
  "ProductId": 1,
  "Status": true,
  "Code": "123456",
  "IsRecall": false,
  "ScanLog": [
    {
      "Location": {
        "type": "Point",
        "coordinates": [
          13.5957758,
          42.7111538
        ]
      },
      "TimeStamp": 201602160957190600,
      "ScanType": 0,
      "UserId": "1004"
    },
    {
      "Location": {
        "type": "Point",
        "coordinates": [
          13.5957907,
          42.7111359
        ]
      },
      "TimeStamp": 201602161246336640,
      "ScanType": 0,
      "UserId": "1004"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

如何通过 TimeStamp 属性对查询结果进行排序?我试过使用这个查询

SELECT c.Code, b.TimeStamp FROM c JOIN b IN c.ScanLog ORDER BY b.TimeStamp
Run Code Online (Sandbox Code Playgroud)

但我收到此错误

Order-by over correlated collections is not supported.
Run Code Online (Sandbox Code Playgroud)

这样做的正确方法是什么?

azure azure-cosmosdb

5
推荐指数
1
解决办法
1834
查看次数

documentdb 模拟器网关服务在启动时崩溃

我正在寻找了解 documentdb 并安装模拟器似乎没有错误。但是,在启动时我有一个服务崩溃:

网关服务启动

从标题来看,我猜这是对模拟器的一项重要服务。有趣的是,模拟器似乎继​​续加载并尝试打开: https://localhost:8081/_explorer/index.html

没有成功。

使用命令提示符我尝试手动启动网关服务,结果如下:

C:\Program Files\DocumentDB Emulator\Packages\GatewayService\GatewayService.Code>documentdb.gatewayservice.exe /?

未处理的异常:System.Runtime.InteropServices.COMException:注册表的值无效(来自 HRESULT 的异常:0x80040153 (REGDB_E_INVALIDVALUE))在 System.Runtime.InteropServices.RuntimeEnvironment.GetDeveloperPath() 在 System.AppDomain.SetupFusionupStore info(AppDomain)InfoSet在 System.AppDomain.SetupDomain(Boolean allowRedirects, String path, String configFile, String[] propertyNames, String[] propertyValues)

C:\Program Files\DocumentDB Emulator\Packages\GatewayService\GatewayService.Code>documentdb.startupentrypoint.exe /?

未处理的异常:System.Runtime.InteropServices.COMException:注册表的值无效(来自 HRESULT 的异常:0x80040153 (REGDB_E_INVALIDVALUE))在 System.Runtime.InteropServices.RuntimeEnvironment.GetDeveloperPath() 在 System.AppDomain.SetupFusionupStore info(AppDomain)InfoSet在 System.AppDomain.SetupDomain(Boolean allowRedirects, String path, String configFile, String[] propertyNames, String[] propertyValues)

C:\Program Files\DocumentDB Emulator\Packages\GatewayService\GatewayService.Code>

网关服务是否相关?知道如何解决吗?

快速编辑:我已按照此处列出的说明进行操作:https : //docs.microsoft.com/en-us/azure/documentdb/documentdb-nosql-local-emulator#troubleshooting

没有生成要通过电子邮件发送的 etl 文件。

提前致谢

azure-cosmosdb

5
推荐指数
2
解决办法
2325
查看次数

C# MongoDB 驱动程序只返回 100 个结果

我正在写一个邮寄标签,需要为每个文件打印一个标签。

我在 Collection 上有 829 个文档,但是当我检索它们时,我只得到 100 个文档。

我有这个 LINQ 代码:

IMongoCollection Pessoa;
Pessoa = database.GetCollection<Pessoa>(collectionName);

return Pessoa.AsQueryable().ToList();
Run Code Online (Sandbox Code Playgroud)

如何检索所有文件?

c# linq mongodb azure-cosmosdb

5
推荐指数
1
解决办法
1181
查看次数

如何在Azure的CosmosDB中使用Django?

我很好奇是否可以使用CosmosDB作为Django项目的数据库后端.

django azure azure-cosmosdb

5
推荐指数
1
解决办法
2746
查看次数

Azure Functions 中的 SQL Query DocumentDB 按整数不起作用

我在 Azure Functions 中使用 JavaScript 语言。使用 Cosmos DB 作为输入时,我无法将整数作为变量进行查询。例如,我有以下内容:

使用 Azure Cosmos DB 作为我的输入(公司)的函数设置。这是使用分区键作为{partitionKey}和我的 SQL 查询作为设置SELECT * FROM c where c.random = {randomId}

在函数的代码中,我发送了以下内容作为我的测试数据:

{
    "randomId": 1,
    "partitionKey": "prospect"
}
Run Code Online (Sandbox Code Playgroud)

有了这个,我没有得到任何结果。我已经确定我有一个random值为 1 的对象。

如果我要向我的收藏中添加random值为 的内容"1",则以下操作将起作用:

{
    "randomId": "1",
    "partitionKey": "prospect"
}
Run Code Online (Sandbox Code Playgroud)

我已经在 DocumentDB API 和 MongoDB API 上尝试过这个,这应该无关紧要,因为绑定内置于 Azure Functions 中。我在不同数据集上看到的趋势是,当您将整数参数绑定到查询或文档 ID 字段中的某些内容时,查询将不起作用。

任何想法如何解决这一问题?

编辑:

我已经通过可用文档确认这在 C# 中有效。

javascript azure node.js azure-functions azure-cosmosdb

5
推荐指数
1
解决办法
1686
查看次数

Azure CosmosDb 在 AppInsights 中显示已取消的操作

我有时会在 Application Insights 的 Failures => failed dependency 中看到此错误: Azure 异常屏幕截图

一直在搜索文档,但在任何地方都看不到提到这一点。此状态是否意味着操作已通过令牌取消,或者是否类似于以前的 400 错误的跨分区响应?(https://github.com/Azure/azure-cosmos-dotnet-v2/issues/606#issuecomment-427909582

另外,此操作是否会重试,或者是否会因此丢失数据?

azure-application-insights azure-cosmosdb

5
推荐指数
0
解决办法
820
查看次数

C# Cosmos DB 补丁 - 将元素插入子集合

尝试将新项目添加到父对象的子集合中。例如,在下面的代码中,如何将一个新项目添加到 Items 集合中?

{
    "id": "SalesOrder2",
    "ponumber": "PO15428132599",
    "OrderDate": "2005-07-01T00:00:00",
    "AccountNumber": "Account2",
    "Items": [
        {
            "Id": 1,
            "OrderQty": 3,
            "ProductCode": "A-123",
            "ProductName": "Product 1",
            "CurrencySymbol": "$",
            "CurrencyCode": "USD",
            "UnitPrice": 17.1,
            "LineTotal": 5.7
        },
        {
            "Id": 2,
            "OrderQty": 2,
            "ProductCode": "A-456",
            "ProductName": "Product 2",
            "CurrencySymbol": "$",
            "CurrencyCode": "USD",
            "UnitPrice": 10,
            "LineTotal": 20
        }
    ],
    "_rid": "BsMkAMc43s4CAAAAAAAAAA==",
    "_self": "dbs/BsMkAA==/colls/BsMkAMc43s4=/docs/BsMkAMc43s4CAAAAAAAAAA==/",
    "_etag": "\"00000000-0000-0000-e136-0dbec04601d7\"",
    "_attachments": "attachments/",
    "_ts": 1637760030
}
Run Code Online (Sandbox Code Playgroud)

做这样的事情:

public async Task AddProduct(Item item)
{
        var response = await CosmosDbContainer.PatchItemAsync<Product>(
        id: "a1dc8286-bb5e-4ac0-beb4-f9f1dfc79711",
        partitionKey:new PartitionKey("a1dc8286-bb5e-4ac0-beb4-f9f1dfc79711"), …
Run Code Online (Sandbox Code Playgroud)

c# azure-cosmosdb azure-cosmosdb-sqlapi

5
推荐指数
1
解决办法
2430
查看次数

如何检查 Docker 容器中的 Cosmos DB 模拟器是否已完成启动?

我们在 Docker 容器中使用 Cosmos DB 模拟器。容器与测试一起启动。有时在第一次测试期间,连接时会出现读取超时,测试会中止。在测试之前我们是否可以运行任何检查来验证 Cosmos DB 是否已完成初始化?例如通过查询特定的URL?

docker azure-cosmosdb azure-cosmosdb-emulator

5
推荐指数
1
解决办法
952
查看次数

当我尝试创建数据库时,azure-cosmos-emulator 挂起

我在 Intel Mac 上,尝试运行 linux azure-cosmos-emulator 模拟器,但每次启动映像并尝试创建数据库时,它都会挂起并且从不创建数据库。容器日志中没有显示任何内容。我该如何解决这个问题或排除故障?

这是我的设置。我究竟做错了什么?

version: '2.4'

## to run:
##  export EXTERNAL_IP=$(ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' | head -n 1)
##  docker-compose up -d

services:

  cosmosdb:
    container_name: cosmosdb
    hostname: cosmosdb
    image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
    platform: linux
    tty: true
    restart: always
    mem_limit: 3GB
    ports:
      - '8081:8081'
      - '8900-8902'
      - '10250-10256'
      - '10350:10350'
    environment:
      AZURE_COSMOS_EMULATOR_PARTITION_COUNT: 10
      AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE: true
      AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE: ${EXTERNAL_IP}
    volumes:
      -  vol_cosmos:/tmp/cosmos.data

volumes:
  vol_cosmos:
Run Code Online (Sandbox Code Playgroud)

注1:该文件夹/tmp/cosmos.data是我的Mac上具有777权限的文件夹。当我启动容器时,我没有看到在此文件夹中创建任何文件。注意2:我还尝试将持久性设置为 false。仍然无法创建数据库。注3:我曾经有过这个工作,但我不知道我做了什么来破坏它。

azure-cosmosdb

5
推荐指数
1
解决办法
1262
查看次数