, free & fully virtual. June 9th - 10th. Register Now, free & fully virtual. June 9th - 10th. Register Now

mongoDB shell - escape sequences in output (response) text - i.e., "help"

Hello - mongoDB beginner user and community beginner, so would be grateful if you could point me towards the right place to pose this question.

Running mongodb community server 4.2.3 on Ubuntu 18.04. I am solely using the shell (command “mongo”) at this point. I am using a very simple terminal emulator which does not process ANSI codes (instead, it prints the control character bytes in decimal so they are visible.)

My question/problem is this - does mongoDB generate ANSI codes as part of it’s output back to a user?

When I enter a command (for example, help), the response I get back includes an echo of the command with some embedded ANSI (ANSI-type?) sequences (each sequence begins with two bytes - [ - followed by another byte or two.

Example: When I type help (and hit the enter key),

I get this response: help[3G[Jhelp[7G

followed by the expected response to a help command: help on db methods … and so on

but with the addition of a tab character (byte value 9) at the start of each line of text.

Here are my specific questions:

  1. Are these control codes being emitted by mongoDB shell, or inserted by the telnet server (telnetd)?
  2. If the control codes are being emitted by mongoDB shell, can they be turned off, so I only get pure text with newlines?

Thanks very much, and again, as I am new to the community, please assist by pointing me to the correct user group if this is not the appropriate place.



Welcome to the MongoDB community @Dave!

The mongo shell uses a fork of the linenoise library which requires a subset of ANSI escape sequences based on VT100 features.

What terminal emulator and TERM environment setting are you using? I’d recommend upgrading to a more capable terminal client, if possible.


Thanks, Stennie for the quick reply!

The ANSI stuff appears only to be generated generated as part of echo from the shell, so that fits very much with “linenoise” which I hadn’t heard of before.

Is it possible to tell mongodb shell to suppress all echoes, so that the only output it generates are responses to commands?

Of course the proper path for me is to harness mongodb driver for the language I’m using ( C ), but for the very first getting-started phase, I wanted to build on my initial interactions with the shell (using a simple program which I wrote), which have gone well otherwise.

Thank you again for the quick and illuminating reply!


Hi Dave,

Can you provide a bit more context on your use case – are you trying to write a script for the shell? What sort of interactions are you scripting? Your example of the help command is a feature specific to an interactive shell session.

You can also pass scripts to the shell from the command line, which is generally better suited for automation if you don’t want to use a driver. I would strongly recommend using a supported driver if you want to have more control over I/O and error handling.

See Differences Between Interactive and Scripted mongo if you are interested in trying to write non-interactive shell scripts. You can include the --quiet option to suppress the normal startup output and warnings from the mongo shell.


–quiet! Cool! No time to test till tomorrow morning, but in a nutshell that sounds promising.

I am doing this AS A RANK BEGINNER (in particular, I like to write “out to the bare metal” and didn’t feel confident trying to write/debug my own interface to the MongoDB “wire” protocol, at this stage, so I figured scripted interface into the shell would be sufficient, given that I have no need for concurrency, “sharding”, or any other special features (yet.)

What I am doing - a simple state machine (written in C) build on top of a home-made telnet client, that watches for a character from mongo (like “>”) and/or a timeout (number of seconds), and given this and state number, do something (send a message to mongoDB like insert one record is the most common case).

All of this works well enough (20 records/second seems to be the fixed ceiling I can find and that’s sufficient for now), so I hope(d) to continue this path (scripting vs mongodb shell) while I’m learning.

PS I really like MongoDB - the more I read about it’s design, my reaction is “that’s nice!”. Congrats to the designers/architects - as a meager beginner, this is a great introduction to the world of noSQL!


1 Like