【问题标题】:Azure cosmosDB: Getting error on sorting with mongoDB apiAzure cosmosDB:使用 mongoDB api 进行排序时出错
【发布时间】:2020-12-16 21:27:35
【问题描述】:

我正在使用 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)]: {}

谁能帮帮我?

【问题讨论】:

  • 您能分享一下您在 Cosmos 中为此集合定义的索引吗?

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


【解决方案1】:

搜索错误消息会出现this page,这表明解决方案是在容器上修复indexing policy。请确保您没有排除要查询的路径。

【讨论】:

  • 该索引策略仅适用于 SQL API。 Mongo 有自己的索引。
猜你喜欢
  • 2021-09-25
  • 2018-08-06
  • 2022-01-22
  • 2018-09-05
  • 1970-01-01
  • 2021-12-01
  • 2020-03-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多