Database Reference
In-Depth Information
Summary
In this chapter, you learned how to enable the sharding feature for a MongoDB database.
First of all, we prepared the environment and configured the hostnames for configuration
servers. Then, you learned how to start a configuration server and establish a configuration
server on a machine. You are recommended to host the configuration server on separate
machines in a production environment, but for development, you can host them on a single
machine.
After establishing the configuration servers, we added shards to sharding. For production
uses, it's better to use a replica set for each shard, but for development and testing environ-
ments, we can host standalone mongod instances. For our example, we added two shards,
one replica set, and a standalone mongod instance.
Also, you learned how to manage and control mongos instances using the mongo shell.
At the end, we created a database and collection to test the sharding feature on. You learned
that we should enable sharding for the database first, then using the mongo shell, we en-
abled sharding for each collection using shard keys. Using JavaScript codes and a for-loop,
we added some test data into the collection.
After adding data to the collection by using a query from the available shards, replica set,
and standalone MongoDB instance, we learned that MongoDB splits data between avail-
able chunks using a defined shard key.
In the next chapter, you will learn how to improve the response time of the server using the
methods that we learned in the previous chapters.
Search WWH ::




Custom Search