sample
创建一个新的数据库use sample
。sample
创建一个简单的集合db.sample.insert({})
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错误吗?报告此类错误的适当方法是什么?
答案 0 :(得分:2)
您没有看到错误;当前,Cosmos DB的MongoDB API不支持复合索引。您的findOneAndUpdate()
应该可以找到没有sort
或具有单一属性sort
的工作。
注意:有一个已发布的UserVoice请求(here)您可以对其进行投票,并且该请求具有产品团队的状态更新;这可能对您有帮助。