Book Image

Web Development with MongoDB and NodeJS Second edition

Book Image

Web Development with MongoDB and NodeJS Second edition

Overview of this book

Table of Contents (19 chapters)
Web Development with MongoDB and NodeJS Second Edition
Credits
About the Authors
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. Use the following command to access the Mongo shell:

$ 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...