One common cause is that an index path corresponding to the specified order-by item is excluded or the order by query does not have a corresponding composite index that it can be served from. The query requests a sort on a field that is not indexed.
Azure Cosmos DB with mongo don't support .sort operation ?
Hi, after trying to query data from cosmos db (configured for mongo), but I got error on .sort({"at": -1})
Everything works on localhost mongo db very well, but not in azure.
Trace back from python is:
2024-04-09T13:02:08.1267872Z Traceback (most recent call last):
2024-04-09T13:02:08.1306576Z File "/tmp/8dc58941c15dbc9/Infinity/Server/_returns.py", line 18, in innerRegistration
2024-04-09T13:02:08.1315265Z tmpValue = f(*args, **kwargs)
2024-04-09T13:02:08.1348454Z ^^^^^^^^^^^^^^^^^^
2024-04-09T13:02:08.1355683Z File "/tmp/8dc58941c15dbc9/Infinity/Api/analysis.py", line 19, in _GetRunningAnalyses
2024-04-09T13:02:08.1389641Z return AnalysisController.GetAnalyses()
2024-04-09T13:02:08.1397553Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-09T13:02:08.1432439Z File "/tmp/8dc58941c15dbc9/Infinity/Analysis/analysis.py", line 64, in GetAnalyses
2024-04-09T13:02:08.1439683Z for i in DB.QueryEntitiesCursor(cls.CT_REQUESTS, {}).sort({"at": -1}):
2024-04-09T13:02:08.1505329Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/cursor.py", line 1264, in next
2024-04-09T13:02:08.1513024Z if len(self.__data) or self._refresh():
2024-04-09T13:02:08.1520545Z ^^^^^^^^^^^^^^^
2024-04-09T13:02:08.1529464Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/cursor.py", line 1181, in _refresh
2024-04-09T13:02:08.1537585Z self.__send_message(q)
2024-04-09T13:02:08.1616121Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/cursor.py", line 1060, in __send_message
2024-04-09T13:02:08.1624920Z response = client._run_operation(
2024-04-09T13:02:08.1632082Z ^^^^^^^^^^^^^^^^^^^^^^
2024-04-09T13:02:08.1700891Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/_csot.py", line 107, in csot_wrapper
2024-04-09T13:02:08.1715095Z return func(self, *args, **kwargs)
2024-04-09T13:02:08.1723368Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-09T13:02:08.1730873Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/mongo_client.py", line 1394, in _run_operation
2024-04-09T13:02:08.1796623Z return self._retryable_read(
2024-04-09T13:02:08.1803733Z ^^^^^^^^^^^^^^^^^^^^^
2024-04-09T13:02:08.1811626Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/mongo_client.py", line 1492, in _retryable_read
2024-04-09T13:02:08.1818927Z return self._retry_internal(
2024-04-09T13:02:08.1827725Z ^^^^^^^^^^^^^^^^^^^^^
2024-04-09T13:02:08.1894053Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/_csot.py", line 107, in csot_wrapper
2024-04-09T13:02:08.1902563Z return func(self, *args, **kwargs)
2024-04-09T13:02:08.1910010Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-09T13:02:08.1917169Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/mongo_client.py", line 1462, in _retry_internal
2024-04-09T13:02:08.1924926Z ).run()
2024-04-09T13:02:08.1995756Z ^^^^^
2024-04-09T13:02:08.2004565Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/mongo_client.py", line 2315, in run
2024-04-09T13:02:08.2012439Z return self._read() if self._is_read else self._write()
2024-04-09T13:02:08.2020872Z ^^^^^^^^^^^^
2024-04-09T13:02:08.2087296Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/mongo_client.py", line 2444, in _read
2024-04-09T13:02:08.2095610Z return self._func(self._session, self._server, conn, read_pref) # type: ignore
2024-04-09T13:02:08.2103908Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-09T13:02:08.2110885Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/mongo_client.py", line 1390, in _cmd
2024-04-09T13:02:08.2117842Z return server.run_operation(
2024-04-09T13:02:08.2181787Z ^^^^^^^^^^^^^^^^^^^^^
2024-04-09T13:02:08.2190476Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/helpers.py", line 322, in inner
2024-04-09T13:02:08.2198087Z return func(*args, **kwargs)
2024-04-09T13:02:08.2206177Z ^^^^^^^^^^^^^^^^^^^^^
2024-04-09T13:02:08.2214347Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/server.py", line 167, in run_operation
2024-04-09T13:02:08.2280454Z _check_command_response(first, conn.max_wire_version)
2024-04-09T13:02:08.2289686Z File "/tmp/8dc58941c15dbc9/antenv/lib/python3.11/site-packages/pymongo/helpers.py", line 230, in _check_command_response
2024-04-09T13:02:08.2297918Z raise OperationFailure(errmsg, code, response, max_wire_version)
2024-04-09T13:02:08.2306330Z pymongo.errors.OperationFailure: Error=2, Details='Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: d9d6af32-94d7-45fc-9da8-2204a6bc5471; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: d9d6af32-94d7-45fc-9da8-2204a6bc5471; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: d9d6af32-94d7-45fc-9da8-2204a6bc5471; Reason: (Message: {"Errors":["The index path corresponding to the specified order-by item is excluded."]}
2024-04-09T13:02:08.2313918Z ActivityId: d9d6af32-94d7-45fc-9da8-2204a6bc5471, Request URI: /apps/ccadfd1a-514d-45de-8701-00c2650cc8e5/services/ac5cdff8-1e51-4471-ac45-1d216ccdf14d/partitions/ab2e4e06-278f-46d7-88c2-ba0284788e8f/replicas/133571385087626579s/, RequestStats: Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum, SDK: Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0);););, full error: {'ok': 0.0, 'errmsg': 'Error=2, Details='Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: d9d6af32-94d7-45fc-9da8-2204a6bc5471; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: d9d6af32-94d7-45fc-9da8-2204a6bc5471; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: d9d6af32-94d7-45fc-9da8-2204a6bc5471; Reason: (Message: {"Errors":["The index path corresponding to the specified order-by item is excluded."]}\r\nActivityId: d9d6af32-94d7-45fc-9da8-2204a6bc5471, Request URI: /apps/ccadfd1a-514d-45de-8701-00c2650cc8e5/services/ac5cdff8-1e51-4471-ac45-1d216ccdf14d/partitions/ab2e4e06-278f-46d7-88c2-ba0284788e8f/replicas/133571385087626579s/, RequestStats: Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum, SDK: Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0);););', 'code': 2, 'codeName': 'BadValue'}
1 answer
Sort by: Most helpful
-
Sajeetharan 2,031 Reputation points Microsoft Employee
2024-04-09T13:44:34.3+00:00