Mongosh --eval freezes the shell

Updating with further fixes;
thanks to Anna’s help, any of the following fixes mongosh failing to terminate on exit (hanging). Tested this on CentOS 7, using MongoDB version 5.0.9, and mongosh 1.5.0, though I suspect any MongoDB 5 and mongosh <1.6 will have the same issue.

  1. prepend to any eval commands, or issue open entering mongosh, the following command; db._mongo._instanceState.evaluationListener.ioProvider.close = () => {};
  2. terminate any eval or mongosh session with process.exit() instead of exit
  3. upgrade to mongosh version 1.6.1

If you can manage it, I’d suggest the upgrade as the best option.

1 Like