问题描述
我正在使用MongoDB API。
if (req.query.sortBy) {
var parts = req.query.sortBy.split(":");
sort[parts[0]] = parts[1] === "desc" ? -1 : 1;
}
try {
// var tasks = await Task.find({owner:req.user._id})
// res.send(tasks)
await req.user
.populate({
path: "tasks",options: {
limit: parseInt(req.query.limit),skip: parseInt(req.query.skip),sort,},})
.execPopulate();
这非常适合在我的本地主机上的MongoDB上执行sortBy = createdAt_asc或sortBy = createdAt_desc。 但是在使用cosmosDB连接时出现错误。 错误是
Error=2,Details='Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 471da3a5-0085-4b62-a447-c8bb1b26dded; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 471da3a5-0085-4b62-a447-c8bb1b26dded; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 471da3a5-0085-4b62-a447-c8bb1b26dded; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 471da3a5-0085-4b62-a447-c8bb1b26dded; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 471da3a5-0085-4b62-a447-c8bb1b26dded; Reason: (Message: {"Errors":["The index path corresponding to the specified order-by item is excluded."]}\r\n` +
'ActivityId: 471da3a5-0085-4b62-a447-c8bb1b26dded,Request URI: /apps/fdd31784-70ac-4bdd-b379-098c33c600e2/services/0b9a2cb6-44f8-45b7-bef9-cbfa6e5673e5/partitions/28daf003-696b-4ce3-ad83-5572e94bbff8/replicas/132429018129211375s/,RequestStats: Please see CosmosDiagnostics,SDK: Windows/10.0.14393 cosmos-netstandard-sdk/3.3.2);););););',code: 2,codeName: 'BadValue',[Symbol(mongoErrorContextSymbol)]: {}
有人可以帮我吗?
解决方法
搜索错误消息会弹出this page,这表明解决方案是将indexing policy固定在容器上。请确保您不排除要查询的路径。