mrsarm / mongotail

Command line tool to log all MongoDB queries in a "tail"able way
https://pypi.org/project/mongotail/
GNU General Public License v3.0
192 stars 17 forks source link

Command values cased as findAndModify or mapReduce cause errors #44

Closed jsbohnert closed 1 year ago

jsbohnert commented 1 year ago

Discovered via the nodeJS mongo native driver issuing findOneAndDelete() commands where the 'command' was cased as findAndModify, instead of the findandmodify currently expected by the text matching in mongotail.

Additional testing showed that it is possible to generate a similar failure with Map-Reduce commands as Mongo similarly will honor casing of 'mapreduce' or 'mapReduce' as the command.


Repro example - findAndModify vs findandmodify:

Working Mongo client invocations:

> db.test.findOneAndDelete({"somefield": 1});

OR

> db.runCommand({"findandmodify": "test", "query": {"somefield":  1 }, "remove": true,"new": false,"upsert": false});

Failing Mongo client invocation (also as issued by JS driver):

> db.runCommand({"findAndModify": "test", "query": {"somefield":  1 }, "remove": true,"new": false,"upsert": false});

mongotail output:

Mongotail EXCEPTION - Unknown command operation
Dump: {"op": "command", "ns": "calypso.test", "command": {"findAndModify": "test", "query": {"somefield": 1.0}, "remove": true, "new": false, "upsert": false, "lsid": {"id": BinData(0,"ASV1ww3RQ3ebaPD8AlXihA==")}, "$db": "calypso"}, "ndeleted": 0, "ts": ISODate("2023-04-01T22:06:59.223Z")}
Mongotail EXCEPTION - Unknown registry
Dump: {"op": "command", "ns": "calypso.test", "command": {"findAndModify": "test", "query": {"somefield": 1.0}, "remove": true, "new": false, "upsert": false, "lsid": {"id": BinData(0,"ASV1ww3RQ3ebaPD8AlXihA==")}, "$db": "calypso"}, "ndeleted": 0, "ts": ISODate("2023-04-01T22:06:59.223Z")}

Repro example - mapReduce vs mapreduce:

Working Mongo client invocations:

> db.orders.mapReduce(    mapFunction1,    reduceFunction1,    { out: "map_reduce_example" } )

OR

> db.runCommand({"mapreduce": "orders", map: mapFunction1, reduce: reduceFunction1, out: "map_reduce_example"});

Failing Mongo client invocation

> db.runCommand({"mapReduce": "orders", map: mapFunction1, reduce: reduceFunction1, out: "map_reduce_example"});

mongotail output:

Mongotail EXCEPTION - Unknown registry
Dump: {"op": "command", "ns": "calypso.orders", "command": {"mapReduce": "orders", "map": "function() {\n   emit(this.cust_id, this.price);\n}", "reduce": "function(keyCustId, valuesPrices) {\n   return Array.sum(valuesPrices);\n}", "out": "map_reduce_example", "lsid": {"id": BinData(0,"CNpTo5aTR6eohBp38syUxg==")}, "$db": "calypso"}, "ts": ISODate("2023-04-02T00:54:21.137Z")}
mrsarm commented 1 year ago

Hi @jsbohnert , thanks for reporting this bug, and provide a PR, going to check it soon.

jsbohnert commented 1 year ago

Thank you, and thanks for the valuable tool - very handy!

mrsarm commented 1 year ago

I've published the pre-release 3.1.1b1 with your patch, you can update to give it a try with:

$ pip install -U mongotail==3.1.1b1

Or use the Docker version using the tag 3.1.1b1.