Databases Reference
In-Depth Information
db.people.find().sort({"email" : 1})
mongos will query all of the shards and do a merge sort when it gets the results to
make sure it is returning them in the correct order. mongos uses cursors to retrieve
data from each server, so it does not need to get the entire data set in order to start
sending batches of results to the client.
db.people.find({"email" : "joe@example.com"})
mongos does not keep track of the "email" key, so it doesn't know which shard to
send this to. Thus, it sends the query to all of the shards in serial.
If we insert a new document, mongos will send that document to the appropriate shard,
based on the value of its "name" key.
Setting Up Sharding
There are two steps to setting up sharding: starting the actual servers and then deciding
how to shard your data.
Sharding basically involves three different components working together:
shard
A shard is a container that holds a subset of a collection's data. A shard is either a
single mongod server (for development/testing) or a replica set (for production).
Thus, even if there are many servers in a shard, there is only one master, and all of
the servers contain the same data.
mongos
This is the router process and comes with all MongoDB distributions. It basically
just routes requests and aggregates responses. It doesn't store any data or config-
uration information. (Although it does cache information from the config servers.)
config server
Config servers store the configuration of the cluster: which data is on which shard.
Because mongos doesn't store anything permanently, it needs somewhere to get the
shard configuration. It syncs this data from the config servers.
If you are working with MongoDB already, you probably have a shard ready to go.
(Your current mongod can become your first shard.) The following section shows how
to create a new shard from scratch, but feel free to use your existing database instead.
Starting the Servers
First we need to start up our config server and mongos . The config server needs to be
started first, because mongos uses it to get its configuration. The config server can be
started like any other mongod process:
$ mkdir -p ~/dbs/config
$ ./mongod --dbpath ~/dbs/config --port 20000
 
Search WWH ::




Custom Search