Database Reference
In-Depth Information
Implementing Sharding
For those involved with large-scale deployments, auto-sharding will probably prove one
of MongoDB's most significant and oft-used features.
In an auto-sharding scenario, MongoDB takes care of all the data splitting and
recombination for you. It makes sure the data goes to the right server and that queries are
run and combined in the most efficient manner possible. In fact, from a developer's point
of view, there is no difference between talking to a MongoDB database with a hundred
shards and talking to a single MongoDB server. This feature is not yet production-ready;
when it is, however, it will push MongoDB's scalability through the roof.
In the meantime, if you're just starting out or you're building your first MongoDB-
based website, then you'll probably find that a single instance of MongoDB is sufficient
for your needs. If you end up building the next Facebook or Amazon, however, you will be
glad that you built your site on a technology that can scale so limitlessly. Sharding is the
topic of Chapter 12 of this topic.
Using Map and Reduce Functions
For many people, hearing the term MapReduce sends shivers down their spines. At
the other extreme, many RDBMS advocates scoff at the complexity of map and reduce
functions. It's scary for some because these functions require a completely different way
of thinking about finding and sorting your data, and many professional programmers
have trouble getting their heads around the concepts that underpin map and reduce
functions. That said, these functions provide an extremely powerful way to query data.
In fact, CouchDB supports only this approach, which is one reason it has such a high
learning curve.
MongoDB doesn't require that you use map and reduce functions. In fact,
MongoDB relies on a simple querying syntax that is more akin to what you see in
MySQL. However, MongoDB does make these functions available for those who want
them. The map and reduce functions are written in JavaScript and run on the server.
The job of the map function is to find all the documents that meet a certain criteria.
These results are then passed to the reduce function, which processes the data. The
reduce function doesn't usually return a collection of documents; rather, it returns a
new document that contains the information derived. As a general rule, if you would
normally use GROUP BY in SQL, then the map and reduce functions are probably the
right tools for the job in MongoDB.
You should not think of MongodB's map and reduce functions as poor imitations
of the approach adopted by CouchdB. If you so desired, you could use MongodB's map and
reduce functions for everything in lieu of MongodB's innate query support.
Note
 
 
Search WWH ::




Custom Search