4

I am using 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();

This is working perfectly to do sortBy=createdAt_asc or sortBy=createdAt_desc on the MongoDB on my localhost. But getting an error when using the cosmosDB connection. the error is

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)]: {}

Can anyone help me with it?

theblue5.o
  • 45
  • 1
  • 5

1 Answers1

0

Searching that error messages turns up this page, which points to the solution as fixing the indexing policy on your container. Please ensure you aren't excluding the path you're querying against.

Noah Stahl
  • 6,905
  • 5
  • 25
  • 36