O'Reilly logo

MongoDB: The Definitive Guide by Kristina Chodorow, Michael Dirolf

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Getting Started

MongoDB is very powerful, but it is still easy to get started with. In this chapter we’ll introduce some of the basic concepts of MongoDB:

  • A document is the basic unit of data for MongoDB, roughly equivalent to a row in a relational database management system (but much more expressive).

  • Similarly, a collection can be thought of as the schema-free equivalent of a table.

  • A single instance of MongoDB can host multiple independent databases, each of which can have its own collections and permissions.

  • MongoDB comes with a simple but powerful JavaScript shell, which is useful for the administration of MongoDB instances and data manipulation.

  • Every document has a special key, "_id", that is unique across the document’s collection.

Documents

At the heart of MongoDB is the concept of a document: an ordered set of keys with associated values. The representation of a document differs by programming language, but most languages have a data structure that is a natural fit, such as a map, hash, or dictionary. In JavaScript, for example, documents are represented as objects:

{"greeting" : "Hello, world!"}

This simple document contains a single key, "greeting", with a value of "Hello, world!". Most documents will be more complex than this simple one and often will contain multiple key/value pairs:

{"greeting" : "Hello, world!", "foo" : 3}

This example is a good illustration of several important concepts:

  • Key/value pairs in documents are ordered—the earlier document is distinct from ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required