TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

MongoDB Shell

MongoDB shell for beginners and professionals with examples on CRUD, insert document, query document, update document, delete document, use database, projection etc.

<< Back to MONGODB

MongoDB Shell

MongoDB have a JavaScript shell that allows interaction with MongoDB instance from the command line.

If you want to create a table, you should name the table and define its column and each column's data type.

The shell is useful for performing administrative functions and running instances.

How to run the shell

To start the shell, open command prompt, run it as a administrator then run the mongo executable:

$ mongo 

MongoDB shell version: 2.4.0
Connecting to: test

You should start mongoDB before starting the shell because shell automatically attempt to connect to a MongoDB server on startup.

The shell is a full-featured JavaScript interpreter. It is capable of running Arbitrary JavaScript program.

Let us take a simple mathematical program:

>x= 100
100
>x/ 5;
20

You can also use the JavaScript libraries

> "Hello, World!".replace("World", "MongoDB");

Hello, MongoDB! 

You can even define and call JavaScript functions

> function factorial (n) {

... if (n <= 1) return 1;

... return n * factorial(n - 1);
... }

> factorial (5);

120

Note: You can create multiple commands.

When you press "Enter", the shell detect whether the JavaScript statement is complete or not.

If the statement is not completed, the shell allows you to continue writing it on the next line. If you press "Enter" three times in a row, it will cancel the half-formed command and get you back to the > - prompt.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf