Possible Atlas bug: $cmd collection doesn't expose all commands

Hi there,

We’ve got a weird situation where a certain command is exposed by db.runCommand but not via the db.$cmds virtual collection on an Atlas cluster.

We are not able to change the way a query is being run because we are using a third party tool which is connecting directly to MongoDB to run the queries. The queries are for example:

db.runCommand({ $query: { count: "collection" } })

and

db.$cmd.findOne({ $query: { count: "collection" } })

Both queries work fine on MongoDB 5.0.7 installed locally; however, on MongoDB 5.0.7 in Atlas I get for the second query (via $cmd):

{ 
    "ok" : 0.0, 
    "errmsg" : "command not found", 
    "code" : 59.0, 
    "codeName" : "CommandNotFound"
}

The command clearly exists, though, because db.runCommand works just fine.

This feels like a bug. It works with the same version of MongoDB locally and works when using db.runCommand, but not via db.$cmds.

I accept the third party tool probably shouldn’t be using these commands, but it’s annoying that it all works locally but not against the cluster.

Please let me know if there’s something I need to enable/fix to make it work.

Hello Adam,

Welcome to the MongoDB Community Forums.

Couple of follow-up questions, please:

  • What type of Atlas deployment are you testing this on? M0, M10, …? Sharded cluster or replica set?
  • Which shell are you using? Legacy “mongo” shell or new “mongosh” shell?
  • What is the third party tool?

Thanks,
Spencer

1 Like

Hi Spencer,

It’s an M2 shared cluster with a replica set. But we spun up an M10 test cluster just to see if it was any different, and it wasn’t.

We’re using the legacy mongo shell, but the third party tool is communication directly with MongoDB (not via a shell of any sort) and sending down a db.$cmd.findOne() command.

The third party tool is the CData MongoDB Connector (we’re trying to get DirectQuery in Power BI working, which the MongoDB BI Connector doesn’t support).

We’ve seen what CData’s sending down the wire, and it’s failing on the db.$cmd execution, so we tried that directly and found the issue. On our local instance of MongoDB, using db.$cmd.findOne({ $query: … }) works just fine, so it’s odd.

I’ve looked into this a little. It seems that “$query” is an artifact in the legacy mongo shell, and has been deprecated since MongoDB 3.2.

Can you tell us what MongoDB driver and version is being used by the CData MongoDB Connector?

Also, when you say “we’ve seen what CData is sending down the wire”, what is it sending down the wire, exactly?