Database Reference
In-Depth Information
query language. Instead of employing a standardized query language such as SQL , you
interact with the server using the JavaScript programming language and a simple API .
If you're not familiar with JavaScript, rest assured that only a superficial knowledge of
the language is necessary to take advantage of the shell, and all examples in this chap-
ter will be explained thoroughly.
You'll benefit most from this chapter if you follow along with the examples, but to
do that, you'll need to have MongoDB installed on your system. Installation instruc-
tions can be found in appendix A.
2.1
Diving into the MongoDB shell
MongoDB's JavaScript shell makes it easy to play with data and get a tangible sense for
documents, collections, and the database's particular query language. Think of the
following walkthrough as a practical introduction to MongoDB.
We'll begin by getting the shell up and running. Then we'll look at how JavaScript
represents documents, and you'll learn how to insert these documents into a MongoDB
collection. To verify these inserts, you'll practice querying the collection. Then it's on
to updates. Finally, you'll learn how to clear and drop collections.
2.1.1
Starting the shell
If you've followed the instructions in appendix A, you should have a working
MongoDB installation on your computer. Make sure you have a running mongod
instance; once you do, start the MongoDB shell by running the mongo executable:
./mongo
If the shell program starts successfully, your screen will look like the screenshot in fig-
ure 2.1. The shell heading displays the version of MongoDB you're running along
with some additional information about the currently selected database.
If you know some JavaScript, you can start entering code and exploring the shell
right away. Otherwise, read on to see how to insert your first datum.
Figure 2.1
The MongoDB JavaScript shell on startup
Search WWH ::




Custom Search