Database Reference
In-Depth Information
What follows is an overview of the components that ship with MongoDB along with
a high-level description of the tools and language drivers for developing applications
with the database.
1.3.1
The core server
The core database server runs via an executable called mongod ( mongodb.exe on Win-
dows). The mongod server process receives commands over a network socket using a
custom binary protocol. All the data files for a mongod process are stored by default in
/data/db. 6
mongod can be run in several modes, the most common of which is as a member of
a replica set. Since replication is recommended, you generally see replica set configu-
rations consisting of two replicas, plus an arbiter process residing on a third server. 7
For MongoDB's auto-sharding architecture, the components consist of mongod pro-
cesses configured as per-shard replica sets, with special metadata servers, known as
config servers , on the side. A separate routing server called mongos is also used to send
requests to the appropriate shard.
Configuring a mongod process is relatively simple compared with other database
systems such as MySQL. Though it's possible to specify standard ports and data direc-
tories, there are few options for tuning the database. Database tuning, which in most
RDBMS s means tinkering with a wide array of parameters controlling memory alloca-
tion and the like, has become something of a black art. MongoDB's design philosophy
dictates that memory management is better handled by the operating system than by a
DBA or application developer. Thus, data files are mapped to a system's virtual mem-
ory using the mmap() system call. This effectively offloads memory management
responsibilities to the OS kernel. I'll have more to say about mmap() later in the topic;
for now it suffices to note that the lack of configuration parameters is a design feature,
not a bug.
1.3.2
The JavaScript shell
The MongoDB command shell is a JavaScript-based tool for administering the data-
base and manipulating data. The mongo executable loads the shell and connects to a
specified mongod process. The shell has many of the same powers as the MySQL shell,
the primary difference being that SQL isn't used. Instead, most commands are issued
using JavaScript expressions. For instance, you can pick your database and then insert
a simple document into the users collection like so:
> use mongodb-in-action
> db.users.insert({name: "Kyle"})
The first command, indicating which database you want to use, will be familiar to
users of MySQL. The second command is a JavaScript expression that inserts a simple
document. To see the results of your insert, you can issue a simple query:
6
c:\data\db on Windows.
7
These arbiter processes are lightweight and can easily be run on an app server, for instance.
Search WWH ::




Custom Search