The basics of MongoDB

Since MongoDB is largely powered by JavaScript, the mongo shell acts as a JavaScript environment. In addition to being able to execute regular Mongo queries, you can also execute standard JavaScript statements. Most of the items mentioned earlier in the JavaScript primer apply directly to the mongo shell as well.

In this next section, we will focus primarily on the various ways to perform standard create, read, update, delete (CRUD) operations via the mongo shell.

The mongo shell

To access the mongo shell, simply execute mongo from any terminal. The mongo shell requires the mongod server to be currently running and available on the machine as the first thing it does is connect to the server:

$ mongo
MongoDB shell version: 2.4.5 ...

Get Web Development with MongoDB and Node.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.