Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo shell tab completion

I was wondering if it's possible to configure the behavior of tab completion in the mongo shell? The two behaviors I've seen are:

  1. The first hit of the tab key completes as far as there's no ambiguity, the second hit shows a list of possible options.
  2. Pressing the tab key completes the full expression according to the first possible option.

I personally much prefer the first option. I've seen both behaviors on different environments (all with mongo version 2 and up), and can't figure out whether it's configurable or caused by the environment.

like image 729
tafi Avatar asked Apr 17 '13 09:04

tafi


People also ask

How do I close Mongo shell?

Note: Instead of typing the exit command, an alternative way to close the shell is to press CTRL + C instead. Now try reconnecting the MongoDB shell to the database server, but this time provide a username and password to properly authenticate into your MongoDB instance.

How run Mongo shell in CMD?

Connect to MongoDB database You can start the server in CMD using the following command. Then type mongo command to run the shell. Now you are in the Mongo shell. If you want, you can run the mongo and mongod without the command prompt.

How do I view collections in Mongo shell?

To list all collections in Mongo shell, you can use the function getCollectionNames().

What is Mongo shell used for?

The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mongo shell to query and update data as well as perform administrative operations.


1 Answers

The mongo shell autocompletion behaviour definitely isn't a configurable option. There are some differences in shell editing behaviour depending on the version of MongoDB you are using.

These differences extend beyond autocompletion to line editing, history, and keyboard shortcuts .. but to confirm your autocompletion observations:

  • MongoDB 1.8.x and older had behaviour #1
  • In MongoDB 2.0.x the shell editing library was changed from readline to linenoise (SERVER-2792) and resulted in a few changes including the tab completion (behaviour #2)
  • As of MongoDB 2.2.x, the original readline-style completion has been restored (SERVER-3809) along with other improvements to shell interaction (eg: SERVER-4321, SERVER-3787, ..).

It is certainly possible to use a mongo shell version which is different than your MongoDB server version if you prefer a given shell's behaviour. To take advantage of all server features and documented shell helpers you generally need a mongo shell version which is the same or newer major version as compared to the mongod version.

like image 117
Stennie Avatar answered Oct 21 '22 07:10

Stennie