O'Reilly logo

MongoDB for Java Developers by Francesco Marchioni

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introduction to the MongoDB shell

MongoDB ships with a JavaScript shell that allows interaction with a MongoDB instance from the command line. The shell is the bread-and-butter tool for performing administrative functions, monitoring a running instance, or just inserting documents.

To start the shell, run the mongo executable:

$ mongo
MongoDB shell version: 3.0.3
connecting to: test

The shell automatically attempts to connect to a running MongoDB server on startup, so make sure you start mongod before starting the shell.

If no other database is specified on startup, the shell selects a default database called test. As a way of keeping all the subsequent tutorial exercises under the same namespace, let's start by switching to the sampledb database: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required