Chapter 2. MongoDB through the JavaScript shell
This chapter covers
- Using CRUD operations in the MongoDB shell
- Building indexes and using explain()
- Understanding basic administration
- Getting help
The previous chapter hinted at the experience of running MongoDB. If you’re ready for a more hands-on introduction, this is it. Using the MongoDB shell, this chapter teaches the database’s basic concepts through a series of exercises. You’ll learn how to create, read, update, and delete (CRUD) documents and, in the process, get to know MongoDB’s query language. In addition, we’ll take a preliminary look at database indexes and how they’re used to optimize queries. Then we’ll explore some basic administrative commands and suggest a few ways of getting help as you continue working with MongoDB’s shell. Think of this chapter as both an elaboration of the concepts already introduced and as a practical tour of the most common tasks performed from the MongoDB shell.
The MongoDB shell is the go-to tool for experimenting with the database, running ad-hoc queries, and administering running MongoDB instances. When you’re writing an application that uses MongoDB, you’ll use a language driver (like MongoDB’s Ruby gem) rather than the shell, but the shell is likely where you’ll test and refine these queries. Any and all MongoDB queries can be run from the shell.