Unable to create a compound index in Azure Cosmos MongoDB, with -1 direction

Aditya 0 Reputation points
2023-03-09T11:17:21.38+00:00

I am not able to create a compound index like this
{'payrollId' : 1, 'reversed' : -1, 'index' : 1}

Its giving me "FAILED"

so i created like this

{'payrollId' : 1, 'reversed' : 1, 'index' : 1}

but now when I run this query

db.xyzCollection.find({'payrollId': '134test'}).sort({'reversed':-1, 'index':1});

It gives me this error

MongoServerError: Error=2, Details='Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 8e2154be-9906-4d75-ac65-e461542955bb; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 8e2154be-9906-4d75-ac65-e461542955bb; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 8e2154be-9906-4d75-ac65-e461542955bb; Reason: (Message: {"Errors":["The order by query does not have a corresponding composite index that it can be served from."]}

db.xyzCollection.find({'payrollId': '134test'}).sort({'reversed':1, 'index':1});

This also gives same error

db.xyzCollection.find({'payrollId': '134test'}).sort({'payrollId': 1, 'reversed':1, 'index':1});
Only this query is working

This is happening only in Cosmos mongodb, the mongodb on my local machine doesn't gives this error
and allows me to create an index with -1

Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,089 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,543 questions
{count} votes