-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
-
QE 2022-06-13
-
15
The shell currently has two separate paths for running find commands: the DBCommandCursor path which is implemented primarily in the JavaScript layer, and the C++ native path. Historically, the former was used for find commands and the latter was used for legacy OP_QUERY find. However, OP_QUERY find is no longer supported by the shell. The only cases in which the C++ path currently get used are for queries against the "$cmd" namespace and for exhaust queries.
The C++ native path is broken when given a negative limit. This trips a tassert in the shell. Examples:
MongoDB Enterprise > db.$cmd.foo.find().limit(-3) {"t":{"$date":"2022-06-08T14:47:06.679Z"},"s":"E", "c":"ASSERT", "id":4457000, "ctx":"js","msg":"Tripwire assertion","attr":{"error":{"code":5746103,"codeName":"Location5746103","errmsg":"DBClientCursor limit must be non-negative"},"location":"{fileName:\"src/mongo/client/dbclient_cursor.cpp\", line:669, functionName:\"operator()\"}"}} Error: DBClientCursor limit must be non-negative MongoDB Enterprise > db.$cmd.foo.findOne() {"t":{"$date":"2022-06-08T14:47:11.579Z"},"s":"E", "c":"ASSERT", "id":4457000, "ctx":"js","msg":"Tripwire assertion","attr":{"error":{"code":5746103,"codeName":"Location5746103","errmsg":"DBClientCursor limit must be non-negative"},"location":"{fileName:\"src/mongo/client/dbclient_cursor.cpp\", line:669, functionName:\"operator()\"}"}} Error: DBClientCursor limit must be non-negative : DBQuery.prototype._exec@src/mongo/shell/query.js:149:40 DBQuery.prototype.hasNext@src/mongo/shell/query.js:302:10 DBCollection.prototype.findOne@src/mongo/shell/collection.js:267:17 @(shell):1:13 MongoDB Enterprise > db.c.find().addOption(DBQuery.Option.exhaust).limit(-10) {"t":{"$date":"2022-06-08T14:47:31.846Z"},"s":"E", "c":"ASSERT", "id":4457000, "ctx":"js","msg":"Tripwire assertion","attr":{"error":{"code":5746103,"codeName":"Location5746103","errmsg":"DBClientCursor limit must be non-negative"},"location":"{fileName:\"src/mongo/client/dbclient_cursor.cpp\", line:669, functionName:\"operator()\"}"}} Error: DBClientCursor limit must be non-negative
The work for this ticket is to fix the shell so that these queries work as expected, which will resolve the linked build failure.
As far as I can tell, there is no reason to use the C++ path for "$cmd" namespaces. I think this relates to some old behavior around pseudo-commands which is no longer relevant. We should just use the normal DBCommandCursor path in this case.
We still need to use the C++ native path for exhaust queries. (Note, however, that SERVER-20770 and SERVER-58491 suggest consolidating the two code paths in the shell.) A good fix for this problem would be to add support for exhaust in the new DBClientBase::find() API and then migrate the shell from DBClientBase::query_DEPRECATED() to DBClientBase::find().
- is related to
-
SERVER-58491 Consolidate the C++ native cursor implementation with the DBCommandCursor-based one in the shell js
- Backlog
-
SERVER-20770 Consolidate the two code paths for running find commands in the mongo shell
- Backlog
-
SERVER-67116 Remove support for applyOps command preCondition field
- Closed
- related to
-
SERVER-66047 Parameter 'limit' is not supported for exhaust queries in Mongo Shell
- Closed