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?

1
  • Can you share the indexes you have defined in Cosmos for this collection? Commented Aug 28, 2020 at 15:46

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

That index policy only applies to SQL API. Mongo has it's own indexing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.