【问题标题】:How do I use the Azure CosmosDB Emulator with the MongoDB API?如何将 Azure CosmosDB 模拟器与 MongoDB API 结合使用?
【发布时间】:2021-03-01 16:57:12
【问题描述】:

我使用 Microsoft Azure Comos Emulator 版本 2.11.11.0。我用命令行启动它:

CosmosDB.Emulator.exe /EnableMongoDbEndpoint=3.6

如果我将应用程序连接到 MongoDB 端点,我会收到以下错误:

com.mongodb.MongoCommandException: Command failed with error 1 (InternalError):
 '[ActivityId=64bdb726-f138-4025-8d5b-ca23bbda384c] Internal error.' on server localhost:10255.
 The full response is {"ok": 0.0, "errmsg": "[ActivityId=64bdb726-f138-4025-8d5b-ca23
bbda384c] Internal error.", "code": 1, "codeName": "InternalError"}

这个错误意味着什么?我还需要做什么才能使用 MongoDB API?

第一个写命令失败:

'{"createIndexes": "fs.files", "indexes": [{"key": {"filename": 1}, "name": "filename_1", "ns": "admin.fs.files"}], "$db": "admin", "lsid": {"id": {"$binary": {"base64": "lFHKYPJ0Rq+ip587pl8YPQ==", "subType": "04"}}}, "$readPreference": {"mode
": "primaryPreferred"}}'

它是从简单的 Java 行产生的:

collection.createIndex( new BasicDBObject( FILENAME, 1 ) );

PS:使用 MongoDb 端点 3.2,这是可行的。应该是模拟器有问题。

【问题讨论】:

  • 不完全清楚错误:您是说尝试创建索引后出现该错误?或者只是想运行mongo shell 之类的东西?
  • 我通过 MongoDB Java 驱动程序接收它。创建索引是我的程序执行的第一个写操作。
  • 我建议编辑您的问题以显示您正在拨打的电话。此外,从错误中,这意味着您正在尝试设置读取首选项。不确定这在 Cosmos DB 中是否受支持。您是否尝试过更直接的方法,例如保存或查找?
  • 我已经添加了 Java 行。我不知道您对阅读偏好的含义。这很简单。问题不是我应该在我的代码中改变什么。问题是我需要在模拟器中设置什么。 InternalError 是什么意思?。

标签: mongodb azure-cosmosdb azure-cosmosdb-mongoapi azure-storage-emulator


【解决方案1】:

使用模拟器 Mongo API 3.6,必须显式创建集合。使用原始 MongoDB 和 Mongo API 端点 3.2,如果创建索引或保存数据,则将间接创建集合。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-06
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多