Why MongoDB Shell use custom console terminal


I have taken look at the MongoDB Shell source code in Github:

I have found out that MongoDB Shell have built in terminal device on which the user enters a stream of data and it manage cursor position etc ( using linenoise that is a readline replacement ) . It read a keystroke from the keyboard and translate it using the function readUnicodeCharacter to get Unicode (UChar32) character.

Why usage of simple code with scanf instead of custom console terminal is not good enough?

char text[256];
printf(“Enter somthing: “);
printf(“text = %s”,text);

Hi @sakdkjkj_jjsdjds,

Line editing libraries like Readline and Linenoise provides extra functionality over just reading raw character input. Linenoise aims to provide common line editing features in a much more concise package than Readline.

Core Linenoise features include support for:

  • Single and multi line editing mode with the usual key bindings implemented.
  • History handling.
  • Completion.
  • Hints (suggestions at the right of the prompt as you type).

The mongo shell version of Linenoise has also evolved with additional keyboard shortcuts and cross-platform behaviour.

However, Linenoise is only used in the legacy mongo shell.

Last year MongoDB introduced a new MongoDB shell (mongosh) with a more modern user experience. The new shell is available as a standalone tool and is also integrated into recent versions of MongoDB Compass.

Unlike the legacy mongo shell, mongosh is in active development and the team is looking for feedback on how the experience can be improved.

For more information see:


1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.