3
  1. 我已经设置了一个公开 MongoDB API 的 Azure Cosmos DB。
  2. 我使用 mongo shell 连接到数据库。
  3. sampleuse sample.
  4. 我创建了一个简单的sample集合db.sample.insert({})
  5. 然后我尝试运行以下查询:
db.sample.findOneAndUpdate({ foo: {"$eq":1}},{ "$set": { "bar":1}},{"sort": { "foo": 1, "bar": 1 }})

当我对一个普通的 MongoDB 3.2.0 实例运行它时,查询成功完成(并匹配 0 个结果)。但是,在 CosmosDB 上,会生成以下堆栈跟踪:

2019-01-31T13:46:49.740+0100 E QUERY    [thread1] Error: findAndModifyFailed failed: {
    "_t" : "OKMongoResponse",
    "ok" : 0,
    "code" : 2,
    "errmsg" : "Message: {\"Errors\":[\"Encountered exception while executing function. Exception = Error: {\\\"Errors\\\":[\\\"The order by query does not have a corresponding composite index that it can be served from.\\\"]}\\r\\nStack trace: Error: {\\\"Errors\\\":[\\\"The order by query does not have a corresponding composite index that it can be served from.\\\"]}\\n   at queryCallback (__.sys.commonUpdate_BsonSchema.js:3835:26)\\n   at Anonymous function (__.sys.commonUpdate_BsonSchema.js:607:29)\"]}\r\nActivityId: ff7b4476-0000-0000-0000-000000000000, Request URI: /apps/c2de8f1c-dee1-4b6c-8543-479a695c3bb2/services/12da6069-653a-45be-bfa1-4394a0798877/partitions/2814e64e-3d06-4705-a346-cbbfc822a49a/replicas/131934057017796979p/, RequestStats: \r\nRequestStartTime: 2019-01-31T12:46:49.6846466Z, Number of regions attempted: 1\r\n, SDK: Microsoft.Azure.Documents.Common/2.1.0.0",
    "$err" : "Message: {\"Errors\":[\"Encountered exception while executing function. Exception = Error: {\\\"Errors\\\":[\\\"The order by query does not have a corresponding composite index that it can be served from.\\\"]}\\r\\nStack trace: Error: {\\\"Errors\\\":[\\\"The order by query does not have a corresponding composite index that it can be served from.\\\"]}\\n   at queryCallback (__.sys.commonUpdate_BsonSchema.js:3835:26)\\n   at Anonymous function (__.sys.commonUpdate_BsonSchema.js:607:29)\"]}\r\nActivityId: ff7b4476-0000-0000-0000-000000000000, Request URI: /apps/c2de8f1c-dee1-4b6c-8543-479a695c3bb2/services/12da6069-653a-45be-bfa1-4394a0798877/partitions/2814e64e-3d06-4705-a346-cbbfc822a49a/replicas/131934057017796979p/, RequestStats: \r\nRequestStartTime: 2019-01-31T12:46:49.6846466Z, Number of regions attempted: 1\r\n, SDK: Microsoft.Azure.Documents.Common/2.1.0.0"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DBCollection.prototype.findAndModify@src/mongo/shell/collection.js:757:1
DBCollection.prototype.findOneAndUpdate@src/mongo/shell/crud_api.js:785:12
@(shell):1:1

CosmosDB 中是否存在一些在普通 MongoDB 实例中不存在的额外查询限制?这只是一个 CosmosDB 错误吗?报告此类错误的适当方法是什么?

4

1 回答 1

2

您没有看到错误;目前 Cosmos DB 的 MongoDB API 不支持复合索引。您findOneAndUpdate()应该找到没有sort或没有单一属性的工作sort

注意:发布了一个 UserVoice 请求(此处),您可以对其进行投票,并且该请求具有来自产品团队的状态更新;这可能对你有帮助。

于 2019-01-31T13:16:19.507 回答