"no such cmd: find" on older versions of MongoDB server

The command {find:"foo"} fails on older server versions such as 3.0 and 2.6 for some reason.
The error returned is

{
        "ok" : 0,
        "errmsg" : "no such cmd: find",
        "code" : 59,
        "bad cmd" : {
                "find" : "foo"
        }
}

Anyone know the command was in those versions that powered the wrapper foo.find()?
Surely, the find() shell method and find() driver methods existed since forever…

Hi @Nuri_Halperin,

The find() method has existed since forever, but the server implementation and wire protocol has evolved significantly since MongoDB 3.0. The original implementation used separate request opcodes so find would have been an OP_QUERY, insert would be OP_INSERT, etc.

Ultimately most of the commands follow a similar format and can be generalised to a single OP_MSG opcode, so legacy opcodes have been progressively replaced by commands in MongoDB 2.6+. Per the Server Wire version and Feature List, the find command was added in MongoDB 3.2.

Drivers use the server’s supported wire protocol version to determine which format to use for commands (and which commands should be supported). MongoDB 5.0 finally deprecated legacy opcodes, so newer drivers and tools will also end up removing logic for versions of MongoDB that are well past end of life.

Each official driver has compatibility tables indicating supported server and language versions (for example: C# and .NET). If you want to connect with a broad range of server versions, I recommend using one of the more established drivers (.NET, Java, Python, …) rather than the mongo shell. The newest drivers introduced (Rust & Swift) only support the MongoDB 3.6+ wire protocol version because all earlier server versions were end of life when those drivers had their 1.0 releases :wink: .

If you just need 2.6 and 3.0 compat I expect the 3.0 mongo shell might be an option for working with those legacy server versions, but you’ll run into issues like O/S support and expiration of the package signing keys.

Regards,
Stennie

1 Like

Thank you so much for the detailed info! You’re the best!

1 Like