如何将 Azure CosmosDB 模拟器与 MongoDB API 结合使用?

我使用 microsoft Azure COMOS 模拟器版本 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,这是有效的。一定是模拟器有问题。

tooy12345 回答:如何将 Azure CosmosDB 模拟器与 MongoDB API 结合使用?

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

本文链接:https://www.f2er.com/838838.html

大家都在问