Chapter 7. Advanced Topics
MongoDB supports some advanced functionality that goes well beyond the capabilities discussed so far. When you want to become a power user, this chapter has you covered; in it we’ll discuss the following:
Using database commands to take advantage of advanced features
Working with capped collections, a special type of collection
Leveraging GridFS for storing large files
Taking advantage of MongoDB’s support for server-side JavaScript
Understanding what database references are and when you should consider using them
Database Commands
In the previous chapters we’ve seen how to create, read, update, and delete documents in MongoDB. In addition to these basic operations, MongoDB supports a wide range of advanced operations that are implemented as commands. Commands implement all of the functionality that doesn’t fit neatly into “create, read, update, delete.”
We’ve already seen a couple of commands in the previous chapters;
for instance, we used the getLastError command in Chapter 3 to check the number of documents affected by an
update:
> db.count.update({x : 1}, {$inc : {x : 1}}, false, true)
> db.runCommand({getLastError : 1})
{
"err" : null,
"updatedExisting" : true,
"n" : 5,
"ok" : true
}In this section, we’ll take a closer look at commands to see exactly what they are and how they’re implemented. We’ll also describe some of the most useful commands that are supported by MongoDB.
How Commands Work
One example of a database command that you are probably familiar with ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access