Book Image

Web Development with MongoDB and Node.js

By : Jason Krol
Book Image

Web Development with MongoDB and Node.js

By: Jason Krol

Overview of this book

Table of Contents (19 chapters)
Web Development with MongoDB and Node.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
12
Popular Node.js Web Frameworks
Index

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
connecting to: test
>

By default, when you first launch Mongo, you are connected to the local server and set to use the test database. To display a list of all databases on the server, use the following command:

> show dbs

To switch databases...