Connecting to a shard in the shell and performing operations
In this recipe, we will connect to a shard from a command prompt, see how to shard a collection, and observe the data splitting in action on some test data.
Getting ready
Obviously, we need a sharded mongo server setup up and running. See the previous recipe, Starting a simple sharded environment of two shards, for more details on how to set up a simple shard. The mongos process, as in the previous recipe, should be listening to port number 27017
. We have got some names in a JavaScript file called names.js
. This file needs to be downloaded from the Packt website and kept on the local filesystem. The file contains a variable called names
and the value is an array with some JSON documents ...
Get MongoDB Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.