I am in need of creating a code to hide/unhide mongo index in node. There are no such methods on node-mongodb-native although they exist on mongo shell.
Second attempt was to run a custom command, but await db.command({ hideIndex: 'some_name' })
ended up with MongoServerError: no such command: 'hideIndex'
.
Lastly, I am aware that in older versions there were execute/eval methods, but it looks like they were removed at some point. I know it poses some security issues allowing someone to run custom commands, but I don't believe no one ever needed something custom to be run from node with the list of methods available in driver being so limited?
Which raises a question: how does one run a custom command in node mongodb driver?
The error directly says what happens, there is no such command. Mongosh has just a wrapper over few more commands to reach behavior you need and this helper doesn't exist in other drivers (at least in most of them). You can check inner steps that executed by
hideIndex
shell helper (by launching this helper without()
) and did them too in the node viarunCommand
(in node it's called justcommand
)