0%

Book Description

Learn how to leverage MongoDB with your Python applications, using the hands-on recipes in this book. You get complete code samples for tasks such as making fast geo queries for location-based apps, efficiently indexing your user documents for social-graph lookups, and many other scenarios.

This guide explains the basics of the document-oriented database and shows you how to set up a Python environment with it. Learn how to read and write to MongoDB, apply idiomatic MongoDB and Python patterns, and use the database with several popular Python web frameworks. You’ll discover how to model your data, write effective queries, and avoid concurrency problems such as race conditions and deadlocks.

The recipes will help you:

  • Read, write, count, and sort documents in a MongoDB collection
  • Learn how to use the rich MongoDB query language
  • Maintain data integrity in replicated/distributed MongoDB environments
  • Use embedding to efficiently model your data without joins
  • Code defensively to avoid keyerrors and other bugs
  • Apply atomic operations to update game scores, billing systems, and more with the fast accounting pattern
  • Use MongoDB with the Pylons 1.x, Django, and Pyramid web frameworks

Table of Contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. Safari® Books Online
    4. How to Contact Us
    5. Acknowledgments
  3. 1. Getting Started
    1. Introduction
    2. Finding Reference Documentation
    3. Installing MongoDB
    4. Running MongoDB
    5. Setting up a Python Environment with MongoDB
  4. 2. Reading and Writing to MongoDB with Python
    1. Connecting to MongoDB with Python
    2. Getting a Database Handle
    3. Inserting a Document into a Collection
    4. Write to a Collection Safely and Synchronously
    5. Guaranteeing Writes to Multiple Database Nodes
    6. Introduction to MongoDB Query Language
    7. Reading, Counting, and Sorting Documents in a Collection
    8. Updating Documents in a Collection
    9. Deleting Documents from a Collection
    10. MongoDB Query Operators
    11. MongoDB Update Modifiers
  5. 3. Common MongoDB and Python Patterns
    1. A Uniquely Document-Oriented Pattern: Embedding
    2. Fast Lookups: Using Indexes with MongoDB
    3. Location-based Apps with MongoDB: GeoSpatial Indexing
    4. Code Defensively to Avoid KeyErrors and Other Bugs
    5. Update-or-Insert: Upserts in MongoDB
    6. Atomic Read-Write-Modify: MongoDB’s findAndModify
    7. Fast Accounting Pattern
  6. 4. MongoDB with Web Frameworks
    1. Pylons 1.x and MongoDB
    2. Pyramid and MongoDB
    3. Django and MongoDB
    4. Going Further
  7. About the Author
  8. Copyright
3.21.12.140