Whether you’re building a social media site or an internal-use enterprise application, this hands-on guide shows you the connection between MongoDB and the business problems it’s designed to solve. You’ll learn how to apply MongoDB design patterns to several challenging domains, such as ecommerce, content management, and online gaming. Using Python and JavaScript code examples, you’ll discover how MongoDB lets you scale your data model while simplifying the development process.

Many businesses launch NoSQL databases without understanding the techniques for using their features most effectively. This book demonstrates the benefits of document embedding, polymorphic schemas, and other MongoDB patterns for tackling specific big data use cases, including:

Rick Copeland

Rick Copeland is the Principal Consultant and Founder at Arborian Consulting, a business focusing on MongoDB and Python custom development and training. Rick is a frequent speaker at MongoDB events, an avid MongoDB enthusiast, and is a charter member of 10gen's "Masters of MongoDB." In the non-MongoDB side of things, Rick is also a well-known Python developer and member of the Python Software Foundation, having contributed to a number of open-source projects and spoken at various evens and user groups.

Rick is also the author of Essential SQLAlchemy, a book published by O'Reilly that introduces the reader to the excellent SQLAlchemy Python database toolkit.

The animal on the cover of MongoDB Applied Design Patterns is the thirteen-lined ground squirrel (Ictidomys tridecemlineatus), also known as the leopard ground squirrel, squinney, or striped gopher. It gains both its Latin name (tredecim meaning thirteen) and common name from the 13 alternating dark and light lines that run down its back and sides. It also has spots within the darker stripes of fur, which help camouflage the animal in its grassland habitat.Thirteen-lined ground squirrels are widespread in the Great Plains region of North America, and in fact are the reason for Minnesota’s nickname “The Gopher State” (though this is a misnomer, as they are not members of the gopher family). Strictly active during the day, this squirrel’s diet consists of grass, seeds, and insects. They prefer open areas with short grass and well-drained soil for creating their burrows. Though they live individually rather than in colonies, there may be as many as 20 ground squirrels per acre in a particularly good habitat.These animals range from 6–11 inches long, and their weight varies widely depending on the time of year. Most usually weigh between 5–6 ounces, but can get near half a pound when preparing for winter hibernation. In preparation, the ground squirrel puts on a heavy layer of fat and stores food in its burrow. Around October, it enters the burrow, rolls into a tight ball, and decreases its respiration to about one breath every five minutes, until it emerges again in March or April.Each thirteen-lined ground squirrel’s burrow is around 15–20 feet long, with several side passages and multiple entrances. With the exception of the hibernation chamber, the burrows are no more than 1-2 feet below the surface. Typically, the tunnel turns sharply near its beginning, to trick digging predators into believing that the burrow has dead-ended.The cover image is from Wood’s Animate Creation.

This book is perfect for anyone wanting to make the transition to using MongoDb. On each chapter the author starts by discussing how a SQL database would approach a specific problem, and contrasts it with one or more ways of approaching the problem in MongoDb. The emphasis is on specific examples that demonstrate solid general principles. There is a good chance that, whatever your project is about, you'll find some examples relevant to it. The chapters on storing log data, content management and social networking were all immediately applicable to my current project, and gave me many ideas on how I would want to structure my database.

I especially appreciated the emphasis the author puts on multiple approaches to each problem, and the tradeoffs of each approach. Special care is taken to point out how those choices affect both writes and queries, and every chapter finishes with a discussion on what factors one needs to consider when sharding their database. Overall there was a lot of concrete, useful advice that I found I could put to practice right away.

Application and database code is presented in either the mongo shell's Javascript or in Python, but the examples are clear enough that you can follow along even without working knowledge of Python.

The author does assume some familiarity with MongoDb and its basic structures. If you have never looked at anything MongoDb related then you will find some portions challenging; I would recommend keeping a more introductory MongoDb reference close at hand. But the book serves its purpose superbly, and without any extra fat. The author is throughout concise and to the point, which I appreciated.

I highly recommend this book to anyone planning to use MongoDb in their projects. Don't start things without it!

I used MongoDB in some of my projects but mostly through adapters (ODMs – object-document mappers). Recently, I needed to think about structure of documents used in one of my web app.

In first part author helps to solve that problem — he shows pros and cons when embedding documents is better solution or when referencing documents wins. In other chapters of Part I. Design Patterns author covers also polymorphic schemas and how to mimick transactional behaviour in MongoDB.

In Part II. Use cases there are different examples of MongoDB in actions. Author provides some Python snippets for each chapter. For me, the most interesting example is storing log data — it is really helpful to be aware of how proper document structure or documents pre-allocation has an influence on database performance.

Making the transition from SQL to NoSQL can do one's head in. I have read countless books, blog posts etc on the subject, I've even been developing MongDB applications for about 18 months now and I have to say that this book has filled in some significant gaps for me. I particularly like that the author has taken the time to constantly refer back to comparable SQL methods, which really helped me to understand the pros of MongoDB. The real-world use-cases in the latter half of the book are golden. Be prepared to have many "aha" moments as you digest this very easy-on-the-brain title. Well done!

MongoDB Design Patterns fills a substantial gap in the MongoDB literature: it explains the challenges particular to application design with MongoDB, and provides complete solutions for a variety of domains. Rick Copeland is one of the foremost independent MongoDB experts; this book's accuracy and thoughtfulness reflect his long experience.